Download

Is this code crappy?

Hi

Been busy with a little game and need to destroy and respawn a little spaceship.

I want a delay before the spaceship is respawned, but if you just put a delay node
before the SpawnActor it does not work.

What I have here works fine, but is there a better/more refined way to do it and will
this way cause problems?

Regards

Shaun

You could “SetLifeSpan” instead. When LifeSpan is set it begins ticking down and destroys itself when it reaches 0.

“Event Destroyed” is then called that you can use to Spawn a new Actor.

Alternatively you could reset your existing actor and avoid destroying it and instead make sure every variable is reset/initialized again.

Hi GarnerP57

Thanks for that!

Unless I do not understand the function fully, I do not think that I could use LifeSpan as it seems
to be a fixed time node? The spaceship in the game will get destroyed when the player makes a
mistake.

Would you mind expounding on your second point as I have no idea how to do that.

Regards

Shaun

An Actor can start with having an infinite LifeSpan (set to 0) and then during Run-Time be set to a LifeSpan other than 0 giving it a finite LifeSpan.

“Event Destroyed” is the event that is called when the Actor is destroyed just like “Begin Play” is the Event that is called when the Actor is spawned.

Somewhere in your game you probably have a count of how many space ships you have left. This could be a good place to spawn a new space ship after “Event Destroyed” was called on the old one.

If you are familiar with Event Dispatchers the space ship spawning Blueprint should bind itself to Event Destroyed when spawning a new space ship so it knows when it was destroyed and can prepare to spawn the next one.

This way the space ships themselves don’t have to spawn the next one but it is instead handled in a persistent Blueprint.

Hi GarnerP57

Being extremely new to this it has taken me the whole night to attempt what you suggested. :o

It is working great and I am getting the nice 2 second delay before the respawn, I however
could only get it working on EventTick, when I used EventDestroyed it would only respawn
once.

Thanks very much for the help. Hopefully I have executed what you suggested.

Screenshot-20180809-21.44.22.png

Screenshot-20180809-21.48.04.png

Regards

Shaun

Hi again Speed777777

You nearly got it but don’t worry I did not thoroughly explain myself.

You need to bind to every new SpaceShip you spawn which you can do while spawning it.

Also note that “OnDestroyed” already exist so you don’t need to make a new “Event Dispatcher”

SpaceShipManager.PNG
Doing it your own way is a good learning experience though so enjoy the ride.

Hi GarnerP57

THANKS FOR THE HELP!!!

Flawless now. :cool:

https://youtu.be/v5JGH5fWlWs

Regards

Shaun