[Behavior Tree] Trouble With Behavior Tree Executing Unexpectedly and Query About Best Practice

Hello all, I’m coming in with a bit of a multi-tier question regarding some issues I’m having developing correct behavior tree functionality for a 2.5D Side Scrolling Fighter I’ve been working on.

The main issue i’m seeing, and I think it relates to the fact that there’s definitely something about behavior trees that i’m missing about how it executes and then proceeds back to the top of the tree, but I’m seeing in certain situations that it’s either

A.) Getting stuck on the final executing task nodes of a certain leaf and never backing back out and returning further up the node to make a new decision.
B.) The final sequence composite of each leaf runs a service to select a “decision” for the AI and I’m finding that, again, in certain cases while it will execute the task nodes and then jump up the tree, it won’t rerun that service and make a new decision when coming back down to it, in some cases getting stuck with a decision it should logically be unable to ever select, I believe staying at the decision from a previous execution.

In this particular scenario if it hits this pathway first it will never break from it (Item A)

In this one, it shouldn’t have been possible for “Attack” to be chosen option, but it seems the service didn’t execute, but kept the decision from a previous execution

I do have the decorators here stuck to abort self and lower if their results ever change, and just by moving the player around that should happen, so it’s weird that in some cases regardless of that it gets stuck in this execution loop.

What I’m generally trying to accomplish with this is for the AI to be able to make a weighted decision based off of certain criteria relating to the players position in relation to the AI.

AI Criteria
1.) Overall distance to player
2.) In the same Y Plane as the player (tolerance provided by the enemy blueprint to make sure it will overlap with it’s attacking hitbox)
3.) Within Melee distance to the player

Decisions the AI can make
1.) Attack
2.) Roam around
3.) Move to a valid attack position to the player
4.) Wait

Based on the level that it meets the criteria there’s about 4 different leaves in the tree with different weighted decisions

For example if we’re not within melee range the attack is a weight of 0, thus a 0% chance of attacking, but if we’re meeting all of that criteria instead it’s a 70 chance of attacking the player, but could also potentially still either roam or decide to wait.

My overall solution has been to create decorators that check each of those options, and from order of “has the most current set as true” to “has the least currently true” hit a leaf that uses a service to make a decision based off of a weighted set passed in.

My biggest issue like I said earlier is I clearly think there’s something I’m missing about how services run and how the execution of the behavior tree handles in all situations, so I could definitely needs some help in pointing out where my current solution is going wrong.

Each set of leaf nodes ends the same, the only difference being the selector composite implementing different decorators and giving different values to the weights in the service



image
image

BTSService_BasicEnemyDecision


BTService_SetWaitTime

Beyond that, as I’m definitively a rather new user to UE, though I’ve taken a few courses, this is my first real project from scratch, so I’d love to get some ideas on what would be a more “professional” way to to achieve the AI functionality I’m aiming for in unreal.

To add some context as to why I’m developing a 2D game in Unreal, while I recognize that the general consensus is that while 2D is not necessarily Unreal Engine’s strength, I’ve had the idea of one kicking around for a while and I wanted to pick a project that was a bit smaller in scope while still giving me a chance to work with engine, as I don’t intend to work on strictly 2D style games. Beyond that, a while ago I picked up a “Beat 'Em Up Game Starter” book for unity that gives a good explanation of the high level concepts I’m working to implement and provides assets for me to use while developing. So I figured trying to take that and implement it in Unreal would be a good test of what I’ve learned from the Unreal courses I’ve previously taken. Thus far it’s actually worked out rather well and I’ve found a way to implement most things, but AI is definitely the area I’ve found transfers the least between the two with the use of behavior trees (in UE) as opposed to some components implementing a bit of scripting (with unity).

I’d say between Paper2D and the release of PaperZD (and tutorials from Code Cobra) working in 2D with Unreal has actually not been too bad and I’ve generally enjoyed it thus far.

1 Like

I’m having a similar issue even with a way simpler tree. Even with a force-succeed decorator I can get stuck within a sequence. Using the BP debug mode I am seeing no execution in the task that the tree is stuck on. I’m beginning to think its a bug but Ill report back if I find something relevant to this thread.