Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Ai controller can never be destroyed or be garbaged collected

In this example I spawn an Ai_Controller with zero references in this level and I can neither destroy it, nor make it get garbage collected. I have attached the test project.


alt text

alt text

Product Version: UE 4.14
1.jpg (204.9 kB)
2.jpg (258.2 kB)
more ▼

asked Feb 02 '17 at 03:00 PM in Blueprint Scripting

avatar image

21 1 3 9

avatar image rotomation May 06 '18 at 03:06 PM

Maybe Un possess is unfit for detach from AI Character!! You Just Need ues "Detach from controller pending destroy" node, Before Destroy Ai controller. Good luck

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Trying this in 4.21.1.

The AiController can't destroy itself "by design", best you can do is Destroy the BrainComponent (ie, The Behavior Tree) and stop tick, which at least will clear up some resources.

In C++ you can GetWorld()->RemoveController(YourAiController); but it doesn't work either...

So I guess AiControllers are here to stay?

more ▼

answered Dec 14 '18 at 07:51 PM

avatar image

1.7k 8 4 8

avatar image VictorBurgos Dec 16 '18 at 12:55 AM

You don't have to do this. It's done automatically for you on Unpossess.

alt text

avatar image Evigmae Dec 16 '18 at 01:38 AM

And yet when you unposses an ai pawn, the behavior tree keeps running unless you manually kill it. just try it. Maybe as much as it's supposed to do it, the engine is not actually fault-proof.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hey UE4Hobbyist,

I'm a bit confused as to why you're spawning an instance of the controller in your level. Could you elaborate on your reasoning for this?

This same setup works fine if the controller is possessing a pawn. For example, if you create a Pawn, assign it an AI Controller, and then inside the Pawn Get AI Controller->Unpossess->Destroy (make sure the AI CON reference is assigned to Unpossess and Destroy) it will destroy it as expected.

Also, I recommend giving this a try in 4.15 to see if the same issue occurs.

Let me know if you have any further questions and let me know the results of the 4.15 test.

Have a great day

more ▼

answered Feb 02 '17 at 04:21 PM

avatar image

Sean L ♦♦ STAFF
43.6k 485 152 442

avatar image Silvio.Terra Apr 18 '17 at 12:50 AM

The steps described still leave an AIController in the level. This was tested with 4.15.1

Tried unpossessing and destroying inside Character's BeginPlay alt text

Tried it in the level blueprint alt text

Yet, there it is, in the world outliner when I hit play: alt text

I know that this AIController belongs that specific Pawn since 1) it's the only pawn in the level and 2) when I set the Pawn's AI controller class to None, no rogue AIController is seen during PIE.

Is there a separate "Destroy" function that you're referring to? DestroyActor is the only one that seems to work with the AIController as the target.

avatar image Sean L ♦♦ STAFF Apr 18 '17 at 05:05 PM

Thanks for the update. I've reproduced the issue and have entered a bug report, which you can track using the link below:


Have a great day

avatar image Silvio.Terra Apr 18 '17 at 07:57 PM

I would like to point out that Controller.cpp specifically overrides DestroyActor with this:

 void AController::K2_DestroyActor()
     // do nothing, disallow destroying controller from Blueprints

So I'm not sure whether this is intended behavior or something that slipped through the cracks (given that one can unposses a controller via BP, unsure why destroy would be forbidden).

For UE4Hobbyist: a workaround would be to write your own C++ function library that takes in an AController* or AIController*, call controller->Unposses(); and controller->Destroy(); directly.

avatar image TaurusI76 Nov 08 '17 at 04:26 PM

This workaround worked in my case. Thank you! However, I wanted to point out to other readers that if you call UnPossess() directly on the 'Controller' pointer of your Pawn, you cannot call Destroy() on it afterwards because UnPossess() nulls the pointer. So the solution here would be to create a pointer to the Controller object and call Destroy() on that. Like so:

 auto controllerRef = Controller;

It's ugly but it works.

avatar image crossmr Oct 02 '18 at 03:23 AM

I've tried to duplicate this in blueprint, but it doesn't seem to be working as the AI controller is still not destroyed. I've followed your logic on this and created an additional reference to the AIController, unpossessed the first one then used the second one for a destroy command, but it didn't seem to work as after killing several pawns, the number of AI controllers in the world never reduced.

alt text

avatar image lotodore Apr 25 '19 at 12:45 AM

This is actually the solution, due to the BP node not doing anything.

avatar image amadlover Jan 07 '19 at 12:27 PM

If bAttachToPawn is checked in the AIController class and i destroy the pawn. the AI Controller object is still in the scene. The mentioned issue says resolved, but i could not find the resolution

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question