Does AIController destroy itself?

I implemented AI with my custom AIController class. I notice that for APlayerController, the game actually destroy the controller once the player exits the game. However, I haven’t seen any example of destroying AIController, so I wonder how will it get destroyed (if at all) ?

Thanks!

It gets auto-destroyed along with the world it was created in, or when last reference to it goes away (like when controlled pawn gets destroyed).

Cheers,

–mieszko

Hi,

Thank you for answering. I just want to clarify on the last reference to it goes away. Does that mean it will be garbage collected?

Here is my scenario: I create a bunch of AI and have them spawn default controller with the custom AIcontroller class that I create. I play the game in the editor, and notice that the name of the controller is

Would the controller get destroyed if I press Stop on the editor ?

Yes :slight_smile:

If you don’t do anything custom the default AI controllers will get garbage-collected one their controlled pawns “die”.

Does it mean that we should not call Destroy() on an AIController? (sorry if I’m bumping up an old question…)

Hi Mieszko,

The problem is that unpossessing and leaving it has a massive performance impact in a large scale game. We need a way of turning it off completely or destroying it. This isn’t optimized:

To optimize AI in a large open world game, developers need a way to turn them off completely when a player isn’t in range.