Hello @Snarkyspider ,
I’ll leave you some corrections I noticed based on the images you shared, which should help your character work correctly when switching states.
First of all, in your Behavior Tree you’re missing the FocusTarget and ClearFocus tasks. These are important so the enemy knows who to look at while chasing or attacking, and to properly clear the focus when leaving the combat state. Without this, the behavior may not work correctly when switching branches.
BTT_FocusTarget
BTT_ClearFocus
Additionally, in the CombatState decorator inside the Blackboard, make sure to set Observer Aborts to Self. In this case it’s better to use Self instead of Lower Priority because what you need is to immediately abort the active branch when the state changes, without affecting other branches of the main selector or forcing unnecessary reevaluations. This prevents previous tasks from continuing to run or constantly restarting while the state has already changed.
In your Attack Task, the delay you added at the end is not necessary. Finish Execute should be set to Success and have ticking enabled, so the Behavior Tree can continue correctly without constantly restarting the task.
Also, in the Attack switch you’re missing an input of type Actor, which basically defines who the enemy is attacking. That same actor should be set using Set Value as Object in the Blackboard, which was previously in the Event Graph and can now be removed from there since it should be handled by the state logic.
The passive state is set correctly
In the Switch on Sight, you’re missing all the code related to the complete detection logic, since right now it’s not correctly handling the flow when detecting or losing sight of the player.
Lastly, in On Perception Updated, inside Handle Sense Sight, make sure you’re correctly passing the Array Element to the Actor parameter of Handle Sense Sight.
With these adjustments, the Behavior Tree should stop constantly restarting and the enemy should switch states in a stable way.
If any other node is still failing, you can send it over and we can check that everything is correctly set up.
Also make sure that your Blackboard keys have exactly the same name everywhere they are set or read. Even a very small change is enough to make the Behavior Tree not work as expected, so I recommend using Ctrl+C / Ctrl+V when referencing key names to avoid typing mistakes.
If this is your first time working with Behavior Trees, a good practice is to follow the tutorial step by step, without adding or removing extra logic at the beginning. Once everything is working correctly, you can start removing or modifying the parts you don’t need. This helps a lot when isolating issues.
I’m also leaving you this document, which might be useful if you want to learn a bit more about Behavior Trees and how they work.
Hope it helps and happy coding!