Giter Site home page Giter Site logo

ashblue / fluid-behavior-tree Goto Github PK

View Code? Open in Web Editor NEW
926.0 26.0 104.0 1.11 MB

Behavior trees for Unity3D projects. Written with a code driven approach on the builder pattern.

License: MIT License

C# 99.55% JavaScript 0.11% Shell 0.34%
unity3d behavior-tree unity3d-plugin ai builder-pattern unity-package-manager

fluid-behavior-tree's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluid-behavior-tree's Issues

PATH_PROJECT in AssetPath describes a folder that never exists

Current project structure of the repo contains Assets/com.fluid.behavior-tree.
The PATH_PROJECT constant in AssetPath.cs is set to Assets/FluidBehaviorTree.
Due to this mismatch, the following console output occurs when attempting to view a behavior tree in the project:
image

Error every frame due to condition in spliced tree

.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()

Contribution Guidelines

A lot of people are making MRs without the proper commit guidelines. Create a PR template to with guidelines to decrease back and forth.

  • Specify to post new feature proposals and feedback to the discussions section
  • For basic troubleshooting (not bug reports) please ask questions on Discord
  • Indicate that commits must be done with commitlint standards (and how to do it)
  • Indicate test suite must pass manually
  • Point user to README.md section on developing

Inject tree in existing tree during runtime

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

  • selector
  • if attacked -> fight
  • if health is low -> flee
  • else do your work ->* injected job specific tree here*

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.

BT window shows all tasks as inactive when EditorApplication.isPaused

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.
image

(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!
image

The automated release is failing 🚨

🚨 The automated release from the 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.


Missing 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 πŸ“¦πŸš€

Logic mislead in TaskParentBase

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.

Test files should not be pulled into builds

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

package.json conflicts when adding to OpenUPM

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!

Decorated TaskBase does not invoke RemoveActiveTask.

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();
        }

Example missing?

Hello,
In the examples, it looks like there is only a blank scene? Am I missing something by chance?

Thanks,
-MH

Repeat Tasks - Not functioning as expected

Repeat tasks are not working as expected. This issue only affects repeaters. Current bugs are as follows.

  • Does not run Start() and Exit() when a task ends, causing tasks like Wait to automatically fail on 2nd run
  • Composites do not work with any repeat tasks

This 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.

  • Prove the issue with a test that shows a sequence/composite does not repeat on completion
  • Write a test to verify nested composites on repeat run as expected repeat
  • Prove the issue with a test that shows Start() and Exit() fails to run task repeat
  • Write a test to verify nested tasks inside a composite run as expected on repeat
  • TaskParentBase should run a self Reset() when success or failure returns
  • TaskBase then needs to run a Reset() on Exit

Testing when the fix is ready:

  • Tree visualizer still works as expected
  • Tree visualizer doesn't blow out with nested repeats
  • Add a nested repeat sample to the sample project that verifies the new repeater logic works as expected

Minor editor rendering glitch

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:
grafik

fluid-behavior-tree version: 2.2.2 (included using the Unity package manager)
Unity: 2019.4.10f1 Personal
OS: macOS 10.15.6

share code with server

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.