AI behavior tree stops running after changing controlled pawn

I have a problem and as always it seems to be like a bug, because it worked in 4.7 and is not working in 4.8.

I have a behavior tree, looks like this:

http://puu.sh/inOzd/0429ade7a5.png

So it’s always running the UpdateBuilding service once a second. The service looks like this:

http://puu.sh/inOHv/c3f68e52c4.png

So it prints out “TickUpdateBuilding” every tick. Really simple.

Now I do this:

http://puu.sh/inOQT/81d030b081.png

I detach the pawn from the AIController, delete the pawn, spawn a new pawn and attach the new pawn to the old AIController. And now the behavior tree stops to run, or at least I stop seeing “TickUpdateBuilding” in the log. In 4.7 it worked without any problems.

If you have a workaround for this until it is fixed (I really hope for a 4.8 hotfix), please let me know. This changing of the pawn while the controller stays the same is the core element of my whole AI, at the moment it’s doing nothing, so the whole game is not working.

This is by design - when a pawn is unpossed its controller’s logic get’s cleared up. The fact that it was working pre 4.8 was an oversight.

There are two things you could do to address that:

  1. Call RunBehaviorTree for every newly possessed pawn.
  2. Override AAIController::UnPossess in your custom AI controller class to bypass the logic-clearing code you don’t need.

Cheers,

–mieszko

1 Like

Thanks for the answer, but why did you change this? It’s making my whole AI not work… Did anyone had problems with the way it was before 4.8? If I would want to make the controller reset everything I could just destroy the AI with controller and respawn the AI with a new controller… So before 4.8 I could achieve both behavior, and now I can’t and you say this is by design?

I tried to override the function but I can’t find it in the override menu:

http://puu.sh/ipOm9/27b981d35e.png

Only OnPosess, but not UnPosess. My project is blueprint only, I can’t do anything in c++.

The important thing for my AI is that the behavior tree is not changing it’s execution, so if it runs a certain task before the pawn changed it has to run the same task after the pawn changed, and most importantly all the blackboard variables need to be 100% the same as before. If I just call RunBehaviorTree on the new pawn this is not the case, right?

I have also tried to not call unposses at all but only possess the new pawn and then destroy the old pawn, but this does not fix it, the behavior tree still stops running.

Please tell me how I can make my AI work again… :frowning:

The reason it has been changed is that it was causing dead AI to have active brains.

It seems there’s currently no way of doing exactly what you need via Blueprints. I can make a quick C++ fix for you if you were willing to compile your binaries from UE4 sources on github.

However, maybe you don’t need that at all. What’s the use case for needing BT to continuously run while you switch the controlled pawn? I mean, we can’t really support it out of the box in a generic case. For example, this would break the behavior if you switched pawns while currently controlled pawn was performing a Move task. Due to the implementation details it could recover, but “new” pawn would not get a new behavior until the previous one finished the move.

Tell me more about your setup, please.

I have no problem with compiling from github, but the problem with such a fix is that it will only work for the current version, right? After 4.8.1 is out it would no longer work and I would have to either use the old 4.8.0 with the fix or 4.8.1 without the fix.

I have written you a detailed explanation on how my AI works in a PM in the forums.

No fixes are made specifically for UE4 sub-versions, the fixes are always done on the master branch, so if you get sources from github then you’ll also get whatever fixes are being made for issues found in current UE4 release. You’ll also get possible bugs that have been introduced in the meantime. It’s not ideal, I know.

I’ll read through your description, pick the best fix and get back to you.

I have the same problem,You can monitor the onPosess within the blueprint and reread the behaviortree, which I guess looks like this. So I’m trying!

I have the same problem,You can monitor the onPosess within the blueprint and reread the behaviortree, which I guess looks like this. So I’m trying!