Forcing a destroy actor through Blueprints

Hello; I’m trying to forcibly destroy some actors using the blueprints, but they seems to be still living the very next frames after their request for destruction, and this causes me problems when I try to spawn a new set of actors in the same position of the previouses.

Letting the game play, I spawn a first set of actors where I ask, then because of a condition not met they get destroyed with the attached script, and then I re-call the spawning methods, but the new actors spawns according to the rules of self-distance between each others I imposed, considering also the actors I thought I had destroyed.

Instead, If I pause the game some frames BEFORE the destruction, and then I frame-skip, the actors seems to be correctly destroyed before the spawn of the new ones.

This is the script I launch to first clear the array referencing all the actors, then all the actors themselves; just to be sure, I then add a Collect Garbage request. I tried also to manually delete all the actors cycling the arrays (before clearing them) and to add a delay.

(I also thought to ask the actors themself if they were in pending kill, before slapping myself for the thought)

It can’t be helped, it a safety mesure to not cause crash because supprice null access, so it wait until it safe, actors are actully only object that you can explicitly destroy, all other object you destroy by not referencing them and making them irrelevent so they get destroyed by GC.

Objects that about to be destroyed are flagged PendingKill and you can check that in C++:

But it seems you cant do that in blueprints, so you need to create bool varable “Is Dead” and set it to true when you destroy actor. Now on your spawn loaction computation you check if Is Dead is true, if it does then you ignore the actor.

Hello.

The work flow I’d recommend you to use when you need some actor be immediately removed from the scene is first hide it and then to the destroy procedure, you may also teleport it to a remote area of the world where it can safely wait its destruction.
Hope this help.

The problem is that I can’t check if “IsDead” is true on an actor that I don’t know if it’s already been destroyed or not, that would have the same effect on checking its “PendingKill” flag

This was the safest way to handle the problem; actually in the end I decided to relax the condition they have to meet to not get destroyed…

If it gets destroyed you would have nothing to compute spawn point (you didn’t described how you do that) with anyway and nothing to check if something is dead, you problem is that it exists for few frames, that means your code see the actor and you need to check if it dead by checking that bool, so i dont see any problem here. PendingKill flag checks are very common in engine code. as for set, you can set IsDead before doing destroy.

And besides blueprint all they can give you is accessed none error and you also can do check valid.

I find wrong to take as “acceptable answer” an access error, that’s why I was avoiding this method; didn’t know I could check for actor validity though.

You can… and how do you exacly list those that you are afraid of access error?

I could add them in an array before destroying them

Or add them when you spawn and remove when destroyed.