ashblue / fluid-behavior-tree Goto Github PK
View Code? Open in Web Editor NEWBehavior trees for Unity3D projects. Written with a code driven approach on the builder pattern.
License: MIT License
Behavior trees for Unity3D projects. Written with a code driven approach on the builder pattern.
License: MIT License
.Sequence("Die")
.Condition("Should Die?", () => State.HasFlag(CharacterState.Dead))
.PathfindingStop()
.AnimancerCrossFade(AnimationDictionary.Animations["Die"])
.End()
//.Sequence("Die Tree")
// .Splice(UnitTasks.Die(gameObject, this, AnimationDictionary.Animations["Die"]))
//.End()
As soon as I click on the View Tree it gets an error,Meanwhile, the Editor window does not display correctly.
Remove call stack. Incorretly tagged user. Need to reach out and figure out who should be tagged instead.
It does not seem like there is a way to call Tick()
less than every frame, due to the way TimeMonitor just wraps Time.deltaTime
. It seems like it should calculate the delta itself in this case.
A lot of people are making MRs without the proper commit guidelines. Create a PR template to with guidelines to decrease back and forth.
Releases are not updating the root package.json
version. Investigate why. Open a ticket with Oyster or the package assembler if the issue is in the corresponding package.
I've seen there is the option to inject a tree in the build process (example in the readme).
However, the Splice method also seems to allow injecting a tree during runtime into an existing one.
public void Splice(ITaskParent parent, BehaviorTree tree);
However, how can I get the correct parent node from my existing tree? Is this feasible?
Would be nice to have something like "BehaviorTree.GetNodeById(string id)" or alike.
Example use case: I plan to have a behavior tree for units like
My units will be assigned to different jobs during their lives (or no job at all) so at the "work" node I'd like to inject/replace a tree "woodcutterbehavior" or "farmerbehavior" or alike. At runtime, obviously.
Sorry if this is kind of a noob question, I'm only just getting familiar with Behavior Trees.
When I pause the editor, the behavior tree shows all the nodes as inactive.
This is unpractical because we want to ideally be able to pause and see exactly what our AI is doing at that particular frame.
(I am using Unity 2022.3.22f1)
I am surprised this issue hasn't been observed before, since when I look at the code it seems quite logical that there would be a bug there. I don't think it's Unity version related.
The state of activation of visual tasks is set to false inside of the OnGUI() method.
This works fine so long as the game is running. But the moment, the game is paused, the OnGUI() method is still running, which means all nodes become inactive.
The solution is to update the state of nodes in a method that runs at the same rate as the Update() function, in this case the EditorApplication.onUpdate. We can't do it in OnGUI because OnGUI() runs many times per frame and is completely unrelated to when the EditorApplication.isPaused is set properly.
=> This snippet is to show the first thing I tried and it doesn't work.
It's because EditorApplication.isPaused is not set to true before OnGUI has had the time to run several times already, so the nodes are set to false.
public void Print ()
{
_printer.Print(_taskActive);
if (!EditorApplication.isPaused)
_taskActive = false;
foreach (var child in _children) {
child.Print();
}
}
Anyway... here's the proper approach:
We print things in OnGUI. But we update values in EditorApplication.onUpdate... And we don't update values when the game is paused.
In BehaviorTreeWindow.cs
void OnEnable() {
EditorApplication.update += OnEditorUpdate;
}
void OnDisable() {
EditorApplication.update -= OnEditorUpdate;
}
private void OnEditorUpdate() {
if (!EditorApplication.isPaused)
_printer?.UpdateValues();
}
In BehaviorTreePrinter.cs
public void UpdateValues()
{
_root.UpdateValues();
}
In VisualTask.cs
public void Print ()
{
_printer.Print(_taskActive);
// _taskActive = false; // <= comment this out
foreach (var child in _children) {
child.Print();
}
}
public void UpdateValues()
{
_printer.UpdateValues(_taskActive);
_taskActive = false;
foreach (var child in _children) {
child.UpdateValues();
}
}
In NodePrinterController.cs
public void UpdateValues(bool _taskIsActive)
{
_faders.Update(_taskIsActive);
}
Now our GUI logic is separated from our value updating logic, and the nodes are keeping their active state even when the game is paused!
master
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can resolve this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here is some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
package.json
file.A package.json file at the root of your project is required to release on npm.
Please follow the npm guideline to create a valid package.json
file.
Good luck with your project β¨
Your semantic-release bot π¦π
In TaskParentBase we have an End method, but this method does not execute. You can check this in TaskParentTest.
So that produces an interesting case when you need to understand was a Parallel task completed. Because all tasks invoke End themselves.
Parallel:
- ActionA (Success)
- ActionB (Continue)
Parallel say us that End will be called when all tasks are completed. But in that case, ActionA call End at the same time us returns Success status.
Hi,
Installing NSubstitute with Unity package manager is required in order for Fluid Behavior Tree to compile properly.
Installation guidelines should mention that.
Best regards
Hi, I wanted to add this package to the OpenUPM registry, but as mentioned here there are some issues with the fact that there are two package.json
files in this project.
As discussed over there, this package has been published already, and adjusting the package.json
to be compatible with OpenUPM might/will break the existing way of publishing it. In my opinion OpenUPM is the more "standard" way of distributing a Unity-specific package compared to the npmjs registry - any chance the suggested changes could be made?
Could also attempt to make the changes myself, but wanted to discuss with the maintainers here first before digging into it.
Cheers!
Currently hard to read the visualizer with Dark Mode. Would be good if more neutral colors were used on the connecting lines.
First, Thank you for useful repo.
I have issue.
Decorated TaskBase does not invoke RemoveActiveTask in decorator.
.Decorator(child=>{
if(!context.CurrentIsDelay() || !context.CanActionTarget()){
child.ParentTree.RemoveActiveTask(child); // should do this for correct working
child.End();
return TaskStatus.Success;
}
return child.Update();
})
.AddNode(new CombatIdleAction(context.Animator))
.End_Decorator()
Is this intentional?
How about that call RemoveActiveTask(child) in End() method ?
If i will get permit, i can make PR.
like this
TaskBase.cs
private void Exit () {
if (_exit) {
OnExit();
}
if (_active) ParentTree?.RemoveActiveTask(this);
Reset();
}
Hello,
In the examples, it looks like there is only a blank scene? Am I missing something by chance?
Thanks,
-MH
Repeat tasks are not working as expected. This issue only affects repeaters. Current bugs are as follows.
Start()
and Exit()
when a task ends, causing tasks like Wait
to automatically fail on 2nd runThis should by fixable by doing the following. Adequate test coverage and testing will be needed to verify this doesn't create any weird bugs in the app.
Start()
and Exit()
fails to run task repeatTesting when the fix is ready:
Thanks for this very nice behavior tree implementation!
I found a minor cosmetic issue, which doesn't seem to affect the functionality or usability:
When rendering behavior trees in the editor, the horizontal lines are a bit off:
fluid-behavior-tree version: 2.2.2 (included using the Unity package manager)
Unity: 2019.4.10f1 Personal
OS: macOS 10.15.6
In script ActionGeneric.cs method OnExit
call initLogic
and OnInit
call exitLogic
.
protected override void OnExit () {
initLogic?.Invoke();
}
protected override void OnInit () {
exitLogic?.Invoke();
}
our project have a online mode, we sperate our server code out of untiy view code.
but fluid-BT uses GameObject as tree owner, i have to change all the owner type to implement this case.
can we change the owner type as a interface?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.