Spawning AI Characters

Overview

This article will give you some step by step instructions and tips on best practices when dealing with spawning AI characters in your game.

Flow Graph Spawning

With the power of Flow Graph at your finger tips, you have many options available to you when it comes to how you want to control the spawning of AI in your level.

Below we'll list a few easy options and from there, your preferred method is completely up to you!

Entity:Spawn

As AI characters are entities, you can use the Entity:Spawn node to spawn AI characters. Check below for a simple example:

  • The Class input is "Human". This information is obtained from this entity being listed under Entity -> AI -> Characters -> Human.
  • The Name input can be whatever you like. You should name the entity to give it a unique name, else it will be empty, which could lead to issues.
  • The Pos input is a simple position location where you want the entity to spawn.

Entity:SpawnArchetype

Similar to the Entity:Spawn node, this node spawns Entity Archetype's specifically. Most AI characters should be setup as Archetypes anyway, so this should be the preferred method.

With this Flow Graph setup, we've expanded a bit on the functionality. We're using an InputKey (which naturally shouldn't be used outside of testing purposes) to trigger a Math calculation, adding +1 to each trigger.

This value is then being sent to the String:Concat node with the "Easy" prefix and our numbered suffix so with each press, the name changes from "Easy1" to "Easy2" to "Easy3" and so on.

Lastly the actual spawning of the Archetype takes place, almost exactly like the Spawn node, but we specify an Archetype path instead and also feed the String:Concat output into the Name input.

Entity:Human

Lastly, probably the least sophisticated way of spawning AI is to enable/disable AI characters that are already placed inside the level.

Simply place AI characters inside the level and with them selected, Add Selected Entity to Flow Graph to expose the available parameters for that AI character.

  • On Game:Start, "Disable" the first AI character and using the Disabled output, also "Disable" the second AI character. This will simply hide and deactivate the AI characters.
  • When Player enters AreaTrigger, trigger "Enabled" on the first character which also triggers for the second. This will unhide and activate the AI characters.
  • Daisy-chaining Nodes like this for enabling/disabling is done simply to keep things more tidy.

Territories and Waves

More advanced methods of spawning large numbers of AI units can be done through Territories and Waves. See AI Territories and Waves for more information.