ObjectRef¶
Namespace:
SideXP.Selection
Reference to an object that can be resolved again after its original instance has been lost (after a domain reload, a scene reload, a switch between edit and play mode or an editor restart).
Remarks
The referenced object is resolved using, in order: - the cached reference, as long as the original instance is still alive - its GlobalObjectId, for assets and objects saved in a scene (edit mode only) - its hierarchy path, for scene objects (including objects not saved yet, or spawned in play mode)
Constructors¶
ObjectRef(Object)¶
Creates a reference to the given object.
Parameters
obj: The object to reference.
Exceptions
ArgumentNullException: Thrown if the given object is null.
Properties¶
Name¶
The display name of the object when it has been captured.
ObjectType¶
The type of the object, or null if that type doesn't exist anymore.
IsSceneObject¶
Indicates if the object is in a scene.
IsPersistent¶
Checks if this reference uses a stable id, so it can be resolved even after the editor has been restarted. Assets and objects saved in a scene have a stable id, while objects not saved yet or captured while in play mode don't.
ScenePath¶
The current path of the scene that contains the object. Empty for objects in an untitled scene or for non-scene objects.
SceneName¶
The name of the scene that contains the object when it has been captured.
HierarchyPath¶
The hierarchy path to the object from the root of its scene, as a readable string. Empty if the object is not a scene object.
Methods¶
Resolve()¶
Gets the referenced object, and caches it if it has been found.
Returns
Returns the found object, or null if it can't be resolved.
GetState(Object)¶
Tries to resolve the referenced object, and gets the state of this reference.
Parameters
obj: Outputs the found object, or null if it can't be resolved.
Returns
Returns the state of this reference.
GetState()¶
Tries to resolve the referenced object, and gets the state of this reference.
Returns
Returns the state of this reference.
Is(Object)¶
Checks if this reference targets the given object.
Parameters
obj: The object to check.
Returns
Returns true if the referenced object is the given one.
RefersToSameObject(ObjectRef)¶
Checks if this reference and the given one target the same object. If at least one of them can be resolved, the resolved objects are compared. Otherwise, their stable ids are compared, or their hierarchy paths if they don't have one.
Parameters
other: The reference to compare.
Returns
Returns true if both references target the same object.
Refresh()¶
Captures again the identifiers of the referenced object, if it's still alive. This is meant to be called after a scene has been saved (so objects not saved before get a stable id), or after an object has been renamed or moved in the hierarchy.
Returns
Returns true if the identifiers have been captured again.
Remarks
Does nothing in play mode, so the stable ids captured in edit mode are not lost.
Clone()¶
Creates a copy of this reference, independent from the original one.
Returns
Returns the created copy.
ToString()¶
Inherited documentation.