CustomInitialize

Introduction

CustomInitialize is a function which is called once per instance when it is initialized. Initialization happens:

  • When an instance is created either in code by using the “new” operator, or if an instance is added through Glue. See below for more information.
  • Whenever an Entity is recycled through a factory.

CustomInitialize and AddToManagers

The CustomInitialize method will only be called when an Entity instance is added to managers. For example consider the following code:

// This assumes that the game has an Entity called Enemy:

// enemy1 will have CustomInitialize called
Enemy enemy1 = new Enemy();

bool addToManagers = false;
// enemy2 will not have CustomInitialize called since it is
// not being added to managers:
Enemy enemy2 = new Enemy(ContentManagerName, addToManagers);

// enemy will not have CustomInitialize called since it is
// not being added to managers (yet):
Enemy enemy3 = new Enemy(ContentManagerName, addToManagers);
// ...but now enemy3 will have CustomInitialize called
enemy3.AddToManagers(null);