Predicted Hierarchy
The Predicted Hierarchy system provides a set of methods for dynamically creating, deleting, and managing objects within the simulation. These methods allow developers to interact with the hierarchy in a way that feels natural and Unity-like, while ensuring that all changes are predictable and synchronized with the server.
Key Methods
Object Creation:
CreateMethods:Instantiates objects in the simulation.
Supports creating objects from prefab IDs or
GameObjectreferences.Optionally allows specifying position and rotation.
Returns a
PredictedObjectIDto uniquely identify the created object.
public PredictedObjectID? Create(int prefabId); public PredictedObjectID? Create(int prefabId, Vector3 position, Quaternion rotation); public PredictedObjectID? Create(GameObject prefab); public PredictedObjectID? Create(GameObject prefab, Vector3 position, Quaternion rotation);TryCreateMethods:Attempts to create an object and returns a boolean indicating success.
Outputs the
PredictedObjectIDof the created object.Fails if prefab id is invalid or prefab isn't part of the registered prefab list.
public bool TryCreate(int prefabId, out PredictedObjectID id); public bool TryCreate(GameObject prefab, out PredictedObjectID id);
Object Deletion:
DeleteMethods:Removes objects from the simulation using their
PredictedObjectID.Handles both pooled and non-pooled objects.
public void Delete(PredictedObjectID id); public void Delete(PredictedObjectID? id);
Object Retrieval:
GetGameObject:Retrieves the
GameObjectassociated with aPredictedObjectID.
public GameObject GetGameObject(PredictedObjectID? id);GetComponent:Retrieves a specific component from the
GameObjectassociated with aPredictedObjectID.
public T GetComponent<T>(PredictedObjectID? id) where T : Component;TryGetId:Retrieves the
PredictedObjectIDassociated with aGameObject.
public bool TryGetId(GameObject go, out PredictedObjectID id);TryGetGameObject:Retrieves the
GameObjectassociated with aPredictedObjectIDand returns a boolean indicating success.
public bool TryGetGameObject(PredictedObjectID? id, out GameObject go);
Prefabs and Pooling
Predicted object creation uses a central
PredictedPrefabsasset referenced byPredictionManager.Prefabs can opt into pooling; pooled instances are kept under a hidden parent for fast reuse.
When reconciling, pooled objects may be disabled/enabled; avoid parenting critical visuals to the root identity if you rely on
SetActivestate — or usePredictedTransform’s optional graphics unparenting.
Spawning Network Identities
Use
PredictedIdentitySpawnerto mirror a set ofNetworkIdentityobjects between server and clients based on prediction state.The spawner coordinates early spawn, observer assignment, ownership, and finalization in both server and verified client passes.
Best Practices
Only create/destroy from within simulation code paths (or via machine/state transitions) to keep behavior deterministic under replay.
Prefer
TryCreateand check the boolean to handle invalid or unregistered prefabs gracefully.Store and pass around
PredictedObjectIDrather thanGameObjectto remain resilient across rollbacks.
Last updated