BehaviorGraph not working as expected with Finite State Machinne

Hi, so I’m trying to do a state machine for enemies, with idle, patrol, chase and attack modes.
When I first did without the finite state machine, it worked like a charm, but now is going back and forward between chase and idle state, when it’s not detecting me in any moment. I know this must be some logic problem, but I don´t get it :frowning:

Chasing when I’m in the area works, and so does attack, but idle is aborting and doing a set state to Chase, even when no target is detected.



Video of behavior
Video of Blackboard

Hi @RafaCrack693

I don’t see anything flagrant from your screenshot. Have you tried to debug the graph to see how the agent loops are behaving?

https://docs.unity3d.com/Packages/com.unity.behavior@1.0/manual/debug.html

On you second screenshot, seems like the Target BBV is null. Could it be that your Chase state abort on the Navigate To Target node because the node has no valid Target?

I also recommend the use of EventChannel (see also) to manage state transition in general.

1 Like

Hi @MorganHoarauUnity, I added some videos to the post, I’ve tried debugging the graph and that’s what shows.

Also, Target is intended to be null when the enemy is not seeing the player, but it fills when the player is on sight, and sets TargetDetected to True. Or that’s how it should work.

also, don’t really get what should I do with EventChannel here, read docu and I’ve worked with some demos, and as you say, I don’t see anyting flagrant in my graph :confused:

Your graph screenshot is not the same as the one on the video. Your Idle abort condition is set to false, just like the Chase state.

You’re right, I might have clicked it without noticing, the result is the same, but it’s not aborting, its failing on Set SpeedMagnitude in Self to 0

I assume this is the SetAnimatorFloat node? Seems like the node is not able to find the animator on self. Can you try to assign directly the animator?

The animator is on another level, yes, de enemy contains the life bar visuals, and inside is the actual enemy with the animator, so I created the self animator to reference it from parent object. However, I don’t think that’s failing, my enemy is running in place because currently it doesn’t have other animation

Sorry if that was not clear, I believe your Self GameObject that is linked to the Set SpeedMagnitude in Self don’t have an Animator attached to it.

Can you check the log in the console? You might be receiving a log warning similar to “SetAnimatorFloatAction No Animator set.”.

Edit: sorry I missed your last message. You are assigning Self instead of SelfAnimator to the node.

I went some steps back in another graph, and maybe the issue is happening because I’m doing Set “TargetDetected” to null every time on repeat, thus making the system to not have anything clear?

In your first graph, you are assigning Self instead of SelfAnimator to the node.

2 Likes

OH MY GOD, you were so right, thank you so much, I changed the name also in the gameObject so that doesn’t happen again. you did truly save me :smiley:

1 Like