I’m trying to set up a system where, after an actor gets destroyed (like when its health reaches zero), a new instance of that actor is spawned at a random location inside a defined area or volume in the level.
How can I do this in Blueprint?
I’m trying to set up a system where, after an actor gets destroyed (like when its health reaches zero), a new instance of that actor is spawned at a random location inside a defined area or volume in the level.
How can I do this in Blueprint?
First off don’t destroy the actor.
Disable its collision and then hide any visual components… Rendering → hidden in game.
Then on “respawn” simply teleport it, enable collision, unhide.
Spawn Zones
Create a new actor to acted as the “spawn volume”. Give the actor a Box collision component.
The box collision will act as the Bounds of the volume… the space in which to consider for spawning.
Collision Settings: NO COLLISION… There’s no purpose for collision.
Box extent scaled to 100x100x100
Then in orthographic left align its base with the grid.
Next Add a Function to Get a Random point inside the collision area.
Drag and drop the actors into the level.
Align and Scale the Collision component as needed per instance.
In the class that’s going to handle “respawning”, presumably the Game Mode, you need to create an array of all the Spawn Zones in the level.
Call a function as some point after the class has initialized.
Begin Play → Sequence → Then 0 → Delay 5 → Get Spawn Zones
Create another function in the same class to grab a random spawn zone from the array.
When you need a spawn point simply call get random spawn zone, use its return to call the Get Spawn Transform
in the spawn zone class.
You can then use this transform to spawn practically anything at that given location.
Here’s another useful video on random spawners:
Unreal Engine Hack & Slash Tutorial [2024] Series | Part 19 | Enemy Spawners