Pausing/disabling AI behavior tree for "stun" in Blueprint?

I was searching for a way to “stun” a character in blueprint, but judging from this answer (How to stop/change a behavior tree using blueprints - Programming & Scripting - Epic Developer Community Forums), it is not very possible. I am wondering if this issue is fixed in 4.5 or if there is any better way to stun a character.

Well you could just do it via variable. Start with a task which checks for that variable, if it’s true wait X (a node in BTs) and if not continue to the other tasks.

Or a variant of this. Maybe a decorator can take this job as well.

But pausing the complete tree seems wrong. You still want it to work. You just don’t want it to move or react. Otherwise you could not do anything while your character is stunned. If you want to add a “un-paralyze” or something later or want to run anything else you won’t have a good time if you remove the tree :wink:

Currently there’s no blueprint way of pausing BT that’s being run (there’s a C++ way, which I shall expose pretty soon).

The legit way to do it on logic level would be to add a boolean key to AI’s blackboard, like IsStunned and in AI’s behavior tree add a high level behavior (left most child of top most composite node [preferably a selector]), like an infinite wait task, that will be guarded with a blackboard-based decorator observing IsStunned's value (Observer aborts: Both). This way the "wait" behavior will be toggled on and off with changes to IsStunned` value.

Cheers,

–mieszko

Would you please specify what will go wrong if I pause the tree and restart it later to “unstun” the character? I am currently doing something very similar and it would be really helpful to know what could go wrong with this.
Thanks for replying!

Thanks for replying, please let us know if we can do that one day.

The workaround I have right now just use unpossess() on AIController, and ask it to possess the pawn again once the stun is finished. It seems to work pretty well and look like something we can also use when stunning the player character, I am still investigating if there is more issues related to it.

Well if you don’t have any case where your AI would have to do anything at all during that time there won’t be any issue.

However that’s the point. You may want to be able to unstun your char or dynamically change that time in runtime (while the stun is lasting). Or you may want to do stuff in your gamemode from the AI. Allow it to be able to communicate with others and so on.

If you can not think of a single case where your AI might have any kind of communication or interaction or state change during the stun time then stopping the whole tree will work just fine.

However if you only prevent parts of the tree from executing you have all kinds of possibilities of still doing something.