SetManagedReferenceIdForObject(Object, object, long)
Assigns a managed reference Id to an object that is referenced using SerializeReference on a specified host.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Serialization
- Assembly: UnityEngine.CoreModule
SetManagedReferenceIdForObject(Object, Object, long)
public static bool SetManagedReferenceIdForObject(Object obj, object scriptObj, long refId)
Parameters
Returns
Type | Description |
|---|---|
| bool | Returns true if the Id was successfully set false otherwise. |
Remarks
In normal usage, it is not necessary to use this method. By default, the Unity Editor automatically generates a unique id for the object when it is first serialized.
If you use this method, it should be called after the referenced object is created and before the next serialization of the host object that references it. If the object is not referenced when the host object is serialized, Unity prunes the object and discards its assigned Id. An object is "referenced" if it is directly assigned to at least one field of the host object, or is referenced indirectly via fields on other referenced objects.
After being assigned, the managed reference id persists as a permanent local identifier for the object provided the object is referenced by the host. This identifier is retained even when the host object is unloaded and reloaded.