Give Page Feedback | API

Component Managers - Component IDs

The IDs assigned to Worlds, Active Grids, and the Component Manager itself are very important to the correct functioning of the Streamable Assets Manager.

ID Pools

There are 5 separate pools of IDs used:

1) Component Manager Pool (exists across the entire project!)

2) Prototype Worlds (per scene)

3) Prototype Active Grids (per scene)

4) Non Prototype Worlds (per scene)

5) Non Prototype Active Grids

Non Prototype Components include both Components added to the scene in the Editor by the developer and Components added at runtime using the API.

Within each Pool, IDs must be unique. For example, a Prototype Active Grid cannot have the same ID as any other Prototype Active Grid within the same scene.

On the other hand, duplicate IDs can exists in different Pools. Using the same Prototype Active Grid referenced before for example, its ID can be the same as the ID found on a Non Prototype Active Grid, or the ID of a Prototype Active Grid found in a different scene.

Saving/Loading Data

The primary importance of IDs is in relation to saving and loading persistent data. They are used in the following way:

1) When Persistent Editor Created Components (Components you add to the scene via the Unity Editor) are destroyed, their IDs are recorded in the persistent data so that they can be re-destroyed each time that data is loaded.

2) When Runtime Persistent Components are created, their IDs as well as the IDs of the Prototypes used to construct them are recorded in persistent data. This allows those Components to be re-created each time that data is loaded.

3) When Persistent Components exist (either added in the Editor or at runtime), data specific to those components is saved with persistent data. The ID of each Component is used to identify which data belongs to which Component.

4) The Component Manager ID is saved with persistent data in order to verify that any loaded data is the correct data for a given scene. It is also used to ensure old save data that needs to be converted is applicable for a given Component Manager.

When using persistent data, hopefully you can see that changing the IDs of Components is a bad idea. If you do so, data will either be discarded, assigned to the wrong Component, or the wrong Prototype will be used to re-construct a Component!

Identifying Components

IDs can also be useful in identifying components at runtime. Rather than assigning Components to other Scripts fields within the Editor, you can make use of a Component's ID in order to get a reference to it. You can use the TryGetWorldByID and TryGetActiveGridByID methods for this purpose.

You will always be able to find Editor added Components using this method, however in order to find Persistent Runtime Created Components, you must call ComponentManager.Load before using these methods.