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.
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.
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:
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.
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.