class
GameObjectCollection
Collection of all game objects associated with a particular scene or prefab.
Provides functionality to patch game object handles as may be needed when deserializing, updating from prefab, applying deltas, and similar.
Also maintains an ECS registry that holds all the entities and components created by its game objects.
Public
Constructors
GameObjectCollection
Methods
~GameObjectCollection
RegisterNewObject
Registers a newly created game object and returns the handle to the object.
- object
- Constructed GameObject to wrap in the handle and initialize.
Returns: Handle to the GameObject.
RegisterExistingObject
Registers a game object that already has a handle.
UnregisterObject
Unregisters the game object.
Handles to this object will no longer be valid after this call.
- object
- Object handle to unregister.
- triggerDestroyEvent
- If true, will trigger OnDestroyed event. Should be true if the object was instantiated and is being destroyed.
GetObject
Attempts to find a game object based on the provided ID.
Returns empty handle if ID cannot be found.
TryGetObject
Attempts to find a game object handle based on the provided ID.
Returns true if object with the specified ID is found, false otherwise.
ObjectExists
Checks if the GameObject with the specified ID exists.
GetObjectCount
Returns the number of game objects registered with this collection.
ReplaceGameObjectInstance
Call this method after you clone/copy/deserialize a new instance of an existing game object.
It will ensure that any existing handles are updated so they point to the newly created object. The old object is expected to be discarded, as they cannot both exist at once.
This works because any old handles will point to the original GameObjectInstanceData, which we just patched to point to the new object.
And any new handles will be patched when we update itself, as our system guarantees that all handles created during a single clone/deserialization operation share the same handle data, so it's enough to just patch this handle.
- newObjectHandle
- Newly created handle pointing to the newly created object.
- originalObjectInstanceData
- Game object instance data of the game object we're replacing.
ChangeGameObjectId
Changes the instance ID of the provided game object.
BeginHandleResolve
Notifies the collection that we are about to register game objects whose handle might not be immediately valid.
This is primarily used during deserialization, as game objects and handles will be registered with the collection during deserialization as they are deserialized, but may be resolved only after deserialization for the entire collection is complete.
Must be followed by EndHandleResolve(), which will resolve any unresolved handles. When handle resolve is active you are allowed to call the following methods:
EndHandleResolve
Ends the handle resolve process started in BeginHandleResolve().
Resolves any unresolved handles by mapping them to the correct game object instance data and correct id.
RegisterUnresolvedHandle
Registers a handle to be resolved when EndHandleResolve() is called.
Unresolved handles are generated during deserialization, as the objects they are pointing to might not be deserialized yet.
RegisterUnresolvedHandleIdRemapping
Notifies the system that id of the object an resolved handle is pointing to has changed.
Useful if you are generating new IDs during deserialization.
- originalId
- Current ID, as registered by RegisterUnresolvedHandle.
- newId
- New wanted ID of the object.
QueueForDestroy
Queues the object to be destroyed at the end of a GameObject update cycle.
DestroyQueuedObjects
Destroys any GameObjects that were queued for destruction.
GetECSRegistry
Returns the ECS registry associated with this collection.
GetECSRegistry
Fields
OnDestroyed
Triggered when a game object is being destroyed.