Begin Destroy -> End Destroy Event

Im doing some prototyping and trying to determine after a OnHit event when the other actor is finally destroyed in BP.

If i run this BP with the delay everything works fine but is very risky to base my game mechanics on a hardcoded timing. When this is clarified would be also very appreaciated an equivalent C++ snippet.

I try to archieve something similar to this in order to know when the actor is finally destroyed.

Can somebody throw some light?

Feel free to ask anything you need.

Why don’t you instead use an event dispatcher? Have it fire off an event call to whoever needs to know when it is destroyed just before calling “destroy” on the actor?

What I want to archieve is just the contrary, know when the actor is completely destroyed to continue with the execution of the script.

Huh? I must be misunderstanding you goals here. In the screen shot above, you are destroying an actor “On Hit”. But you want to know “when” the actor is destroyed (this will happen nearly instantaneously). BUT if you need to know something is destroyed BEFORE resetting the component just use the method I described above. What you’re doing is kind of silly. Once you call “destroy” on an actor it will be removed at the next pass of “garbage collection”.You are literally splitting “frames” here. It isn’t necessary.

I know its kinda strange to need something like this but let me explain the functionality I want build. I have a boomerang who gets an array of collision spheres as targets, when he hits them I want them to be destroyed and continue with the next target in the queue.

When the boomerang hits a target the projectile movement stops completely, you can read more about in this thread and to get it going to the next target I have to run SetUpdatedComponent.

The problem comes now. When I do this without any delay, the collision sphere is not completely destroyed and (I think) fires some more hit events before destroyed making my boomerang not going on. And that’s why I need to know when is this component is completely destroyed and not only “marked for destroy”.

TL;DR:
With delay → works like a charm.
No delay → stops in the air.

Maybe try using “Set Collision Enabled” and on overlap, disable, and destroy. Then give the projectile a new target. Then you don’t have to worry about when “exactly” it is garbage collected.

Yeah, I already migrated all the logic to the BeginOverlap event but I am still wondering how to know when something is completely destroyed.

If in the future I encounter a situation where only works with Hit event then I’ll need this again.

I want to thank you for your patience and time. I know I am being obstinated but when I destroy something I want a way to wait until its completely garbage collected and not have to workaround it.

The moment you call destroy on an Actor you really should consider it Destroyed and forget about the work the garbage collector is doing. If you want to destroy something in the next frame it should be okay to set a delay with a value of 0.

Again, your issue isn’t when the memory is actually released (garbage collection). Unless your game is using every last bit of memory and you MUST wait for memory to free up to do something (which would create a game with like 0 frames per second) you don’t need to worry about when something is “garbage collected”. Your issue is getting a homing projectile to find a new target once it reaches the current target. Garbage collection has absolutely nothing to do with that. Games don’t wait for things to be “garbage collected” before continuing on with code. You don’t want a collision sphere interacting with the world anymore, hide it and turn collision off. Now it is invisible to the player and your “code”. It is as if it doesn’t exist. The ONLY thing that knows the collision sphere still exists is your computer’s memory. So unless there is some reason why you need to free up memory space what you’re asking for is a moot point. I didn’t provide a “work around” A “work around” is something that you do to get something to work with code that isn’t the best but you can optimize/find a better solution later. What I provided was an actual solution to your problem. Also, just reread your post above. I recommended overlap because it is what came to mind. You can do the same logic using the “On Hit” event. So this part of your answer:

"If in the future I encounter a situation where only works with Hit event then I’ll need this again."

doesn’t really need to be an issue. I wasn’t saying change “On Hit” to “On Begin Overlap”. What I meant was, whatever event you use for when the projectile reaches its target, immediately after that disable collision, destroy and set new target.

Oh, now I understand. Then we can close this now. Im happy that I have learned something new today and sorry for attitude before, I didnt wanted to sound rude.

GarnerP57, thank you also :slight_smile: