Contenido del Curso
Unreal Engine FPS Game
Unreal Engine FPS Game
Setting up the enemy spawn points
It is true that we can just drag and drop the enemy blueprints into our scene and they will work just fine! But to make the game more interesting, we want to have specific points where the enemies spawn from during the game.
In our level design document, we have specified where these points are. Now what we need to do is to set up a system which spawns the enemies at these points.
We do this using a blueprint that we create and call BP_Spawner. This spawner blueprint is in charge of spawning enemies and deciding whether they will be moving enemies or stationary enemies.
-
Go to our Blueprints folder, and create a new blueprint class and choose Actor.
-
Add an Arrow component and rotate it
90
degrees on the y axis so when we place it, we see where the enemies will spawn. -
Go to the Event Graph and create a new event by right clicking and looking for Add Custom Event. Call it
Spawn Enemy
. -
Drag out of its execute pin and search for delay, put the value of
1
in the delay node. Then drag out of it and look for Spawn AI From Class node. Under Pawn Class chooseBP_EnemyChar
, then grab the arrow component into the graph and get its World Location.
Drag out of the Return Value pin and cast to BP_EnemyChar
. Create a variable and call it IsAMovingEnemyReference
. Make it editable (the eye icon) and expose it on spawn.
Drag out of As BP Enemy Char and look for Set Is A Moving Enemy then connect the boolean variable that you just created to it.
Open BP_EnemyChar
blueprint and create a new variable and call it EnemySpawnerReference
. Set the type to be BP_EnemySpawner
.
Go back to the spawner blueprint and drag out of the As BP Enemy Char and promote it to a variable. This is a reference to the spawned enemy that this specific spawner created, so call it accordingly and then drag out of the set node’s blue pin and look for Set EnemySpawnerReference. Drag out of the blue pin Enemy Spawner Reference and type self and choose Get a Reference to Self.
Find your Event BeginPlay
and drag out of its exec pin and look for SpawnEnemy and wire it up.
Go back to your BP_EnemyChar
and find the Event On Component Begin Overlap that you created in the previous sections. Then move the two Destroy Actors to the right to make some space and then Get the EnemySpawnerReference
variable. Drag out of it and call SpawnEnemy. Wire it up like so:
That is it! Replace the enemy blueprints in your level with these spawners and run the game! You should see that the enemies spawn once you start the game, and when you destroy an enemy, there is a new one spawning from its spawner!
¡Gracias por tus comentarios!