Problem with spawner

Hi guys I am creating this little mechanic that when you go forward the main coin is destroyed and then you spawn the main copy. So i have to iterate with this idea but the problem is, that when i destroy the copy i also lost the copy of the main coin. How can I get the reference of the object after destroying it?


Hello,
I believe you can’t get the reference if the object is already destroyed. However, if you want to do that, instead of destroying it, you can just set the actor visibility to hidden and make any collision response to ignore. By doing that, you can still get a reference to the coin, and your player point of view can’t see the coin.

I think youd need to destroy SELF actor and have a validated get for the spawned coin at the beginning. If valid then do nothing if not valid spawn coin, or some other reference for the coin needs to be destroyed.

Or take it even further by not destroying the coin ever, hide, move it to new position → show. Or, start using Event Dispatchers:

Every time an actor of class is destroyed, spawn an actor of that class.

1 Like

i’ve set the node up with the Event Dispatchers but it’s not working because when i destroy the first actor than the ondestroyed event won’t fire off. maybe because i only destroyed the object once?

and what is the meaning of this symbol? →

I feel you’re overcomplicating the whole thing. How close is this to what you’re after:

  • coins destroy themselves when stepped into:

  • the spawner respawns them (this script goes there):

Sounds a bit like we’re tacking an endless runner, but who knows.

The main issue is this:

image

Once it’s destroyed, it’s gone. This script belongs in the coin itself, or in the player.

Now it’s working but when i enter in the game the coin will be respawned only tree times and then it stop.

I have to make a loop for like spawning it for 20 times?

What I posted has no limit. What you did is not the same, the new actor’s OnDestroyed is never bound. There is a good reason why a custom event is used there - so we can reuse the same script again and again.

now is working fine. thank you so much for the advices :)))

1 Like