Runtime Spawner

Runtime Spawner

The Runtime Spawner component is the master ‘brain’ of the package. It handles the logic for the spawning and controls any number of Local Area Spawners that you would like to add into a scene.

Adding a Runtime Spawner

To add a Runtime Spawner into your scene, right click in the Scene hierarchy and choose ‘Create Other ⇒ Runtime Spawner’

This will add a new Game Object into your scene called ‘Runtime Spawner’ with the core Runtime Spawner component added.

Configuring the Runtime Spawner

The Runtime Spawner inspector only shows what features you are using at any given point in time. The default settings are shown below. You’ll notice that all of the options are unchecked. By default, the Runtime Spawner does nothing. You need to choose how you want to configure the spawning in your game.

The ‘Samples’ that ship with the Runtime Spawner provide a few example configurations of how you might use the Runtime Spawner in your own game.

These will be described in more detail in the ‘Installing Samples’ section below.

There are 4 basic variations for how you can use the Runtime Spawner in your game. Check the Samples section for more details.

  1. Basic Global Spawner

  2. Local Area Spawner (Biome)

  3. Wave Spawner

  4. Combined

Properties

There are a wide range of options available in the Runtime Spawner to configure the spawning in your game. Some are only shown if a parent selection is enabled. For example the ‘Global Spawners’ property is only visible if you enable the ‘Use Global Spawners?’ option. This allows us to keep the inspector clean and tidy.

Auto Launch on Start

Should object spawning start immediately when the game starts? In most cases you will want to check this box, however there is also a fully documented API that you can use to manually control the Runtime Spawner from script, should you choose to.

Note if Auto Launch on Start is false, you will need to call StartSpawners() yourself to start the spawning!

For example:

var spawner = FindObjectOfType<RuntimeSpawner>(); spawner.StartSpawners();

Note that you will need to reference the namespace for the Runtime Spawner to use the above code, like so:

using PixelWizards.Spawner;

Look at the RuntimeSpawnerControl script that is included in the Samples for an example of using this approach or check out the full Runtime Spawner API documentation for more information on the rest of the API included with the package!

The Player Object

This holds a reference to the Player game object in the scene. Simply drag your player into the field.

All spawning happens in a bubble around the player during gameplay. If left empty, the spawner will use the camera (as defined by the MainCamera tag) as the reference point. It is recommended to use the player instead however.

Note: If you spawn your player dynamically (or otherwise), you can also configure the Player Object at runtime using the SetPlayer() method.

For example:

var spawner = FindObjectOfType<RuntimeSpawner>(); spawner.StartSpawners();

Note that you will need to reference the namespace for the Runtime Spawner to use the above code, like so:

using PixelWizards.Spawner;

Check out the full Runtime Spawner API documentation for more information on the rest of the API included with the package!

Player Tag

The Player Tag maps to one of the Tags that you have configured in your project.

IIt is optional, and can be used to tell your AI objects where the players are in the scene.

The default is ‘Player’

World Extents

This property defines the size of the spawn area in your world. It should ideally encompass the entire playable area of the world that you have built. You can visualize the extents by clicking the ‘Show’ button.

Minimum Spawn Range

Defines the minimum distance to the player that the Runtime Spawner should spawn AI objects. Objects will spawn at a distance between this range and the ‘Culling Range’ (if you are using Internal Culling), and as such, the Minimum Spawn Range should be a lower value than the Culling Range. Ideally your minimum spawn range will be far enough away from the Player so that they do not see the objects ‘Pop’ into view, but instead appear (and disappear) seamlessly as they players move through the level.

Note that if you are using the Wave Spawner and have Wave SpawnPoints that are outside of this range, they may inadvertently get culled if you are using the internal culling system provided by the Runtime Spawner.

The relationship between the Minimum Spawn Range and Culling Range are shown in the incredible artist rendering below. As such, the Minimum Spawn Range MUST be lower than the Culling Range.

Use Internal Culling

The Runtime Spawner will optionally cull any AI Objects that have been spawned when they get too far away from the Player.

Culling Range

Culling Check Frequency

Spawner Tag

Optional property - if you want to add a specific ‘Tag’ to your spawned AI objects, enter it here.

Max Global Population

This field controls the master population of this Runtime Spawner. It will override any specific population controls specified by any of the sub spawn systems (global, local or wave).

Use Global Spawners?

Check to enable Global Spawners. Global Spawners will spawn anywhere on the navmesh within the World Extents of this spawner. Enabling this will activate the Global Spawner section of the Runtime Spawner UI.

Create

When Use Global Spawners is enabled, you can ‘Create’ a new Spawn Entry scriptable object directly from the inspector.

Global Spawners

This defines the list of Spawn Entry AI Agents for this spawner. You can create a new Spawn Entry scriptable Object by clicking on the ‘+’ button, which will prompt you to save

Restrict to Navmesh Areas

Restricts the Global Spawner AI Agents to only spawn on specific Navmesh Areas within the map. Check the Unity Navmesh Area documentation for more information about Navmesh Areas and how to use them

Layer Mask

Only spawn AI Agents on a specific Layer within the scene.

For example, you may set up ‘Ground’ and ‘Building’ layers and only have the AI Agents spawn on the Ground layer.

Min Global Object Count

Max Global Object Count

These two properties define the number of AI Agents that you wish to spawn in the global context for this spawner. The Runtime Spawner will spawn a random number of agents between these two numbers.

Note: may be overridden by the ‘Max Global Population’ setting (see above).

Use Region Spawners (Biomes)?

Check to enable Region Spawners. Region Spawners will spawn anywhere on the navmesh within the World Extents of this spawner. Enabling this will activate the Region Spawner section of the Runtime Spawner UI.

Init

When Use Region Spawners is enabled, an ‘Init’ button will appear. Clicking this will search the Runtime Spawner child hierarchy for any Local Area Spawners that may be present and automatically add them to the Spawn Regions list. Note: only child objects of the parent Runtime Spawner will be searched.

Spawn Regions

This list defines the spawn regions that will be used by this spawner. You can click the ‘+’ button to add a new Spawn Region to the scene. The size of the trigger (the Box Collider) defines the spawn area.

See the Local Area Spawner section below for details on the parameters for Spawn Regions.

Show / Hide Spawn Region Volumes

This button will show / hide the Spawn Region gizmos in the scene view

Use Wave Spawners?

Check to enable Wave Spawners. Wave Spawners will spawn AI Agents as defined by the Wave Spawner configuration. Enabling this will activate the Wave Spawner section of the Runtime Spawner UI. Waves are spawned as defined by a ‘Wave Trigger’ component. You can add a new Wave Trigger by clicking the ‘+’ button on the Wave Triggers UI.

Wave Triggers

Waves are spawned as defined by a ‘Wave Trigger’ component. You can add a new Wave Trigger by clicking the ‘+’ button on the Wave Triggers UI, which will add a child Game Object with a Wave Trigger component attached.

Check the Wave Triggers section of the documentation for more information on the Wave Triggers and its properties.

Show / Hide Wave Triggers

This button will show / hide the Wave Trigger gizmos in the scene view

Log Entries to the Console

Enabling this will log information from the Runtime Spawner into the Unity Console.

Last updated