4.23.1 When an actor with AI controller is destroyed AI controller remains in World Outliner

Is this a bug?

Pawn or Actor?

When a Pawn is destroyed, any Controller it has should be destroyed via DetachFromControllerPendingDestroy().

I am currently using Characters for the AI to possess. My brains jumbled actors and characters since I use Destroy Actor to destroy either.
After a bit of work to understand what was going on, it turned out that the AI controller does get destroyed when I destroy the AI possessed characters.

However, if the player possesses the character and it is destroyed without the player un-possessing it and without the AI controller repossessing it, the AI will still linger in the world outliner, regardless of who the owner is.
Even if I do a Get All Actors of Class on the AI controllers and Destroy them, nothing seems to happen.

I don’t know if I am missing something. There could be a way to destroy the AI controllers that I am not aware of.

I have uploaded a test project I used to test possessing and destroying characters with AI controllers:
Possess and destroy the characters. Then try to delete the remaining AI controllers in the world outliner.
The controls are written as big text in the level provided.

DownloadLink

What you describe is as expected.
As soon as a new controller - in this case, the player - possess the character it will no longer have any association with the previous controller - in your case, the AI.
You will need to manually destroy the AI at some time.
If you don’t need the AI once the player possesses the character, just destroy it then.
Otherwise, keep track of it in some other fashion, such as a variable on the character itself.

If he knew how to destroy it then he would probably.
I have the same problem currently. I set up the Unpossess event in the controller and call destroy on it yet nothing happens. Tested it, the destroy does get called but the controller is still there (I even have a tick event print stringing it’s display name so I know if something changes even ingame).
If I find out anything I will report it here just in case it helps someone.

Apparently it’s a known issue: https://unreal-engine-issues.herokua…issue/UE-44114

Found a solution. Sort of easy, sort of plebean…
Instead of calling destroy on my AIController. I made a pawn class that has it’s default AIController set to NONE (so it doesn’t spawn one) and when I want to destroy my AIController I just spawn one of these, possess it and then destroy the pawn, which will take the controller with it. Roundabout, maybe, but works from what I see.

1 Like

Ahh, so the Blueprint version of DestroyActor isn’t actually hooked up to anything.That’s annoying.
From the looks of it, you can call DetachFromControllerPendingDestroy instead.
It will unposses the pawn and call Destroy() if the controller doesn’t have a playerstate.

So if I call destroy actor on my player state, will my controller destroy properly now?

I have been using that for respawns since .24
seems to work fine but it needs a delay on the respawn process.

I had the same trouble but fixed it with this – just use get controller → setlifespan and put in a time like .1

No problems after using that, meant I can leave dead AI bodies in the world after having big battles, without any controllers running logic, but I could still chop the bodies up with the built in pawn logic… fun times

4 Likes

BlockquoteI had the same trouble but fixed it with this – just use get controller → setlifespan and put in a time like .1
No problems after using that, meant I can leave dead AI bodies in the world after having big battles, without any controllers running logic, but I could still chop the bodies up with the built in pawn logic… fun times

This works well in 4.24, thanks heaps for the suggestion!