Check if object has been spawned in world

I am trying to create a system where when a Enemy mesh is spawned, a ai controller is going to be spawned and possess it. The reason I’m doing this is so that I can respawn the enemy and reuse the Controllers without getting unused memory.

The steps I think so far are:

In my game blueprint, I spawn the enemy blueprint.
In the characterbase class of my enemy, I spawn a ai controller if a new enemy mesh has been spawned
I possess it
When it’s destroyed, I unpossess,
destroy the mesh,
and that ai controller will keep checking whenever the new enemy mesh will be spawned.

My problem here is that I don’t know how I would check if a new enemy has been spawned.

Do I create a variable of object and set it with the return node of the spawn whenever I spawn anything new?

And what happens with that variable when I have more than one of the same type of enemy?

Any other suggestions?

Thanks in advance :smiley:

I wouldn’t try reusing AIControllers until I have CPU or memory issues.

But it you really have to do that no specific waiting is required. If you spawn an actor via blueprint then once the blueprint node is done the pawn is already spawned and you can posses it. Just remember to configure your pawn blueprint to not auto-spawn an AI controller automatically (the Auto Posses AI property).



Thanks a lot! So wandering controllers are not something that I should be worrying about then?

Nope. In the default case controllers will get killed along with their pawns.

So am I ok to just destroy them or do I unpossess first and then Destroy?

Just call Destroy on the Pawn.