Improve Performance (and Ease of Coding) Using a Reference List for your A.I. – Unity3D Bolt Micro-Tutorial

This entry is part of a series of tips I am creating as I make my game.

You can use Bolt for free by downloading it from the Asset Store.

Details

What we need: A Bolt List of GameObjects Scene Variable, and a Flow Graph attached to each A.I. entity. Feel free to attach it to your player character as well if you need to include them.

Input: No inputs.

Output: A List of GameObjects that represents the entire collection of currently active entities.

How this saves you time: Creates an easy-to-reference list of all your A.I. entities each time one is created or exists at the start of the game. You can use this list as a reference for many scripts, such as if you want to save all the active entities in the game.

Summary: Efficiency is a huge deal in video game coding, and one way we can increase efficiency is by reducing the ‘search-time’ when looking for GameObjects in our scene. Functions like Find(), when run every frame, cause an enormous pull on resources. Not only does this address that issue, but it makes it easier for us to code by giving us an easy-to-reference list of our active A.I. Entities. This runs once, at either the start of the game or when an A.I. Entity is instantiated.

Output

Here you can see a Scene-wide list of my active characters, both the Player and the A.I. Entities.

How to Implement

To implement, create a Scene Variable called activeEntitiesInGame of type List of Game Objects on a Variable Module somewhere in your scene (wherever you prefer to store your scene variables). In my case, I use an empty GameObject called GAME_MANAGER and child empty GameObjects to it that have names indicating what their purpose is:

Next, add the Flow Graph module to an object in your A.I. Entity’s hierarchy and create a Flow Graph like the one shown below:

Easy as that! Now, every time Start() is executed the entity will add itself to the List.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: