08 Enemy Spawner

Setting up the enemy spawner.

In this tutorial we’ll create a schematic spawning enemies at a randomly selected spawn point in the scene. We’ll use the schematic in 3 Auto Machines to spawn the 3 different enemies repeatedly.

Enemy Spawner: Schematic #

First, we’ll set up the schematic. Since the spawn points we’re going to use are game objects defined in the scene, we’ll use an actor for that.

Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.

Settings #

We need an actor for the spawn points and a prefab resource for the enemy prefab.

Actors #

Click on Add Actor to add an actor.

  • Actor Type
    Select Game Object.
    We’ll add the used game objects of the actor in the machine’s inspector.

Prefabs #

Click on Add Prefab Resource to add a prefab resource. The used prefab will be defined in the machine’s prefab using resource overrides.

  • Name
    Set to Enemy.

Spawn Prefab #

Add Node > Game Object > Prefab > Spawn Prefab

This node is used to spawn a prefab. We’ll use it to spawn the enemy prefab at a randomly selected spawn point (actor).

  • Prefab
    Select Prefab 0: Enemy.
  • Keep Reference
    Disable this setting.
    No need to waste resources to remember the spawned prefab, this is a fire-and-forget type of spawn.
  • Target Type
    Select Object.

Target Object #

  • Object
    Select Actor 0: Game Object (Scene).
  • Spawn At
    Select Random.

And that’s it for the schematic – click on Save Schematic and save it as EnemySpawner in Assets/Schematics/.

Enemy Spawner: Auto Machine #

Select the EnemySpawner game object in the scene hierarchy, we’ll add the enemy spawner schematic to it using an auto machine. The spawn points we’re going to use are child objects of this object.

Zombunny #

Add an auto machine component to the game object (e.g. using the component menu: Makinom > Machines > Auto Machine). Change the following settings.

Start Settings #

  • Start
    Enable this setting.
  • Repeat Execution
    Enable this setting.
  • Repeat Delay (s)
    Set to 3.

Machine Execution Settings #

  • Schematic Asset
    Select EnemySpawner.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Actors #

Click on Add Actor Object multiple times to add 9 game object selection fields to Actor 0. Select SpawnPoint 1 to SpawnPoint 9 in the selection fields.

The game objects are child objects of the EnemySpawner game object.

Resource Overrides #

Expand the Resource Overrides to change the used prefab.

  • Override Prefabs
    Enable this setting.

Click on Add Prefab to add a prefab that will be used.

  • Prefab
    Select Zombunny.
    The prefab can be found at Assets/Tutorial Resources/Prefabs/.

Condition Settings #

We’ll only want enemies to be spawned when the player is alive.

Click on Add Condition, we’ll set up the variable conditions here.

  • Auto Check
    Select None.

In the added Condition 0, we’ll set up our variable condition.

  • Condition Type
    Select Variable.

Click on Add Variable.

  • Condition Type
    Select Template.
  • Template
    Select Is Alive.
  • Game Object (User Object)
    Select Player.
    This’ll check the machine’s game object, i.e. the player.

Zombear #

Copy the previous auto machine component by right-clicking on it’s name and selecting Copy Component. Add the copy by right-clicking on the name again and selecting Paste As New Component.

Change the following settings in the new auto machine component.

Start Settings #

  • Repeat Delay (s)
    Set to 5.

Resource Overrides #

Expand the Resource Overrides to change the used prefab.

  • Prefab
    Select ZomBear.
    The prefab can be found at Assets/Tutorial Resources/Prefabs/.

Hellephant #

Again, paste the copied component by right-clicking on the name and selecting Paste As New Component.

Change the following settings in the new auto machine component.

Start Settings #

  • Start Delay (s)
    Set to 5.
  • Repeat Delay (s)
    Set to 30.

Actors #

Remove 5 of the added Actor 0 game objects and select HSpawnPoint 1 to HSpawnPoint 4 instead of the currently selected game objects.

The game objects are child objects of the EnemySpawner game object.

Resource Overrides #

Expand the Resource Overrides to change the used prefab.

  • Prefab
    Select Hellephant.
    The prefab can be found at Assets/Tutorial Resources/Prefabs/.

And that’s it – don’t forget to save the scene.

Testing #

Click on Play to start the game. The enemies will now spawn randomly at the spawn points, hunt the player and attack him.

This concludes the survival shooter game tutorial series for now. You can add additional content to the game, e.g. new levels and enemies or power ups (e.g. increasing the player’s damage or decreasing the fire timeout).