I have a problem with "destroy actor"

I have a problem with “destroy actor”
There are error logs happen when I try to use “destroy actor”.
The code is so simple just begin play and then destroy an actor.
However, there are 2 line of error logs happen saying that attempt to access error because the object’s being killed

How could I solve this problem. Is anyting about game instance or game mode?

Look forward to see the answer
Please help me!!!

Hi Phys_Fuku

The “Destroy” function is doing as it should.
Your error is telling you something is trying to access this actor (or at least its reference) once it goes into pending kill mode.

I would do a search for all references in your blueprints and in the world and make sure nothing is still trying to point to it.

Hope this helps

Just to tack on to this, if you do find out when you are referencing the actor after it is destroyed, you can pull a pin off of that actor reference and search for “?IsValid” to make sure you only get the actor reference if it is not being destroyed.

Dear Alex

Thank you very much for your answer, I really appreciate that.
I tried to figure out what cause the problem by unpin all destroy actor node
and then re-pin every single one each time but the error log still happen.
Finally I choose the “?IsValid” method which mmmmGoodDinner recommend.
Though it’s work, I’m not sure whether it causes any problems which may affect the project
in the long term.
Is it OK to do this without finding exact problem?

Best Regards
Phy’s Fuku

Again, the error isn’t from the destroy actor node, it’s from you calling a reference to the actor that is currently being destroyed. So, for example, if you try to destroy an actor, and in that same bp you call a function like SetActorLocation, the program is trying to set the location of an actor that’s being destroyed. That’s why you are getting the error.

So you have to go through and check all of the spots (especially in the on tick function) where you are doing something to change the actor that is eventually going to be destroyed. If you add the isvalid function at that spot, you should be totally fine.

Usually it’s safe to add isvalid anywhere, provided you don’t need to do the stuff after the isvalid function when the actor is destroyed.

Thank you very much for your help and thank for unreal hub too!

Hi Phys_Fuku

Glad we were able to solve your problem.

Controlling logic flow and handling relationships between objects in Unreal is something you really learn with experience, making sure references are valid before use is a good approach providing you understand why these validations may fail in particular situations (this will make debugging easier in the future).

Could you mark this as answered so it may help other people who may have similar issues?

Have a great day.


1 Like

IsValid solved my issue with Timeline errors when Destroying actors. Thanks a bunch!