Help: Spawning Ball

Hey all,

Newbie here trying to learn Blueprints. I’m building a really basic physics thing for just batting a ball around in a room to learn Unreal Blueprints.

I’ve gotten the ball to spawn at the beginning of the level using an array of target points but am having trouble getting the ball to respawn after the actor is destroyed when hitting the goal.

Here’s the destroy and spawn call blueprint:

and here is the spawn function being called:

I’m not too sure why it isn’t working - I feel like I’ve been bashing my head against this for hours and hours somewhat embarrassingly.

Any thoughts as to why this isn’t working?

Latent Action + Garbage Collection.


When the actor gets destroyed, it calls Delay and is then placed on a stack to be removed from memory. The Spawn New Ball function never gets called - by the time it’s time to call it (after 0.1s), the Ball Actor that was supposed to do it no longer exists. Simplifying a bit but that’s the gist.

The respawn functionality should be moved outside of this very actor so another entity that does still exists after the ball has been destroyed can execute that delayed action.


  • if this is the ball actor:

image

  • it could be respawned like so:

Above, note I’m doing the respawning in the Level Blueprint - this script can be placed anywhere, apart from the ball actor itself, though. The Destroyed Actor input on the Custom Event is of Actor Object Reference type - it’s required here as this is the signature of the On Destroyed delegate.


trying to learn Blueprints

An alternative approach here would be to never destroy the ball. Hide it, and show it again in a new location after some delay. Spawning, destroying and having the remains scooped up by the GC is somewhat computationally expensive (once we go into hundreds+), while hiding / moving actors around is virtually free by comparison.


Also, functions and latent actions do not mesh well. If you wanted to wrap the respawn functionality in a function, you could do it like so:

And then:

But it still requires an event which will happily work with delays. And lastly, you could trim some wires like so:

Again, this could be in the Player Controller, Pawn, even Game Mode. Normally, one would write another actor - a spawn manager that controls and oversees the spawning behaviour.

2 Likes

This is such a thoughtful explanation - thank you so much for this! It worked like a treat in the Level BP! I really appreciate the less expensive version for processing as well - this is majorly helpful since it’s in VR.

1 Like