I’m trying to learn how to use the behavior tree and started by making a very simple behavior tree. The AI checks if it can see the player character, if it can in goes to the player’s location, if not it moves to a random location and waits for 2 seconds (imagem below).
It worked well but the AI kept moving towards the player even when the player was already dead.
So, as you can see, I also added a second decorator to check if player is dead. I want to make the AI to go back to moving to random locations if the player is already dead. I set a boolean variable in the player BP named “IsDead” that is set when the health reaches zero. Using print string I can see that the variable is working correctly.
In the AI controller BP I used this variable to set the behavior tree Key (named “IsPlayerDead”):
Then I used this key in the decorator, thinking that it would work as a condition (like the “can see player” decorator).
However, this decorator seems to have no effect whatsoever. I tried moving it up before the “Is Player Dead” decorator, but it didn’t make a difference. It’s funny because the “CanSeePlayer” boolean is set in the same AI Controller event as the “IsPlayerDead”, and the CanSeePlayer decorator works correctly (it chases when the player is in sight but stops chasing if the player is not in sight), I even tried changing the nodes order so it sets IsPlayerDead before CanSeePlayer, but it didn’t make any difference.
I found some very old threads where people talked about a bug in the Behavior Tree that makes it not update the variables correctly, but I don’t know if that’s the case or if I’m doing something wrong.