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.
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.
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.