ActorHandle
Summary
Represents a lightweight, zero-allocation handle wrapping an actor in a scene.
Remarks
Danger
All calls made within this class MUST be performed on the Master Thread. See Threads.RunLater on how to safely call this from an asynchronous thread. Failure to comply with this can cause catastrophic failures as the engine is not designed for concurrent scene mutation.
Definition
Namespace: SDT4.Managed.Core
Assembly: SDT4.Managed.Core.dll
struct ActorHandle
Implements:
IEquatable<ActorHandle>
Fields
| Name | Type | Description |
|---|---|---|
public readonly NativeHandle |
UInt32 | Native entity handle. |
public readonly Scene |
Scene | Native scene pointer. |
Properties
| Name | Type | Description |
|---|---|---|
public get; GlobalId |
Guid | Gets the persistent globally unique identifier of the referenced actor. |
public get; ScopeId |
Guid | Gets the unique identifier of the hierarchy scope containing this actor. |
public get; LocalId |
UInt64 | Gets the scope-local identifier of the referenced actor. |
public get; set; Name |
String? | Gets or sets the display or debug name of the actor, or |
public get; IsValid |
Boolean | Gets a value indicating whether the actor is a valid, active instance in the scene. |
public get; ScopeRoot |
ActorHandle | Gets the top-most root actor handle in the current hierarchy scope. If the actor is the top most, it will return itself. |
public get; Mobility |
Mobility | Gets the mobility state of this actor (e.g. static, stationary, or dynamic). |
public get; Parent |
Nullable<ActorHandle> | Gets the handle of this actor's direct parent in the transform hierarchy, or |
public get; Children |
ActorHandle[] | Gets an array of handles representing all direct children of this actor in the hierarchy. |
public get; Components |
IActorComponent[] | Gets an array containing all components currently attached to this actor. |
Methods
public Boolean HasComponent<TComponent>()
Summary: Determines whether this actor has a component of the specified type attached.
Returns:
- Boolean:
if the component is present; otherwise, .
public TComponent GetComponent<TComponent>()
Summary: Retrieves the attached component of the specified type.
Returns:
- TComponent: The component instance.
public Boolean TryGetComponent<TComponent>(out TComponent component)
Summary: Attempts to retrieve an attached component of the specified type.
Parameters:
component(TComponent): When this method returns, contains the component instance if found; otherwise,.
Returns:
- Boolean:
if the component was found; otherwise, .
public TComponent AddComponent<TComponent>()
Summary: Instantiates and attaches a new component of the specified type to this actor.
Returns:
- TComponent: The newly created component instance.
public Boolean RemoveComponent<TComponent>()
Summary: Removes the component of the specified type from this actor.
Returns:
- Boolean:
if the component was found and removed; otherwise, .
public Nullable<ActorHandle> GetActorByLocalIdInScope(UInt64 localId)
Summary: Resolves an actor handle within the same hierarchy scope matching a scope-local identifier.
Parameters:
localId(UInt64): The scope-local identifier of the target actor.
Returns:
- Nullable<ActorHandle>: The matching actor handle, or
if no matching actor exists in scope.
public ActorHandle CreateEmptyActorInScope(String? name)
Summary: Spawns a new empty actor belonging to the current actor's hierarchy scope.
Parameters:
name(String?): The optional debug or display name to assign to the new actor.
Returns:
- ActorHandle: The handle of the newly created actor.
public Nullable<ActorHandle> CreatePrefabActorInScope(PrefabAsset prefab, String? name, Object? payload)
Summary: Creates an actor from a prefab asset. This will instantiate a new instance of actors from the prefab chain, and optionally initialise a script if the prefab has one. This will insert it within the scope of the current actor.
Parameters:
-
prefab(PrefabAsset): The prefab asset to instantiate. -
name(String?): Optional actor name; if, no name is assigned. -
payload(Object?): Optional script payload provided to the ActorScript.OnCreate callback.
Returns:
- Nullable<ActorHandle>: A valid ActorHandle if instantiation succeeded; otherwise,
if creation was vetoed.
public TActor AsScript<TActor>()
Summary: Resolves the typed script instance associated with this actor if it exists.
Returns:
- TActor: The script instance cast to
, or if not found or the type does not match.
public Actor AsActor()
Summary: Returns the associated script instance as an Actor, or instantiates a new managed representation if none exists.
Returns:
public virtual Boolean Equals(Object? obj)
Summary: Determines whether the specified object is an ActorHandle and matches this instance.
Parameters:
obj(Object?): The object to compare with this instance.
Returns:
- Boolean:
if the object is an ActorHandle referencing the same entity and scene; otherwise, .
public Boolean Equals(ActorHandle other)
Summary: Determines whether the specified ActorHandle references the same native entity and scene.
Parameters:
other(ActorHandle): The handle to compare with this instance.
Returns:
- Boolean:
if both handles reference the same native entity within the same scene; otherwise, .
public virtual Int32 GetHashCode()
Summary: Returns the hash code for this actor handle.
Returns:
- Int32: A 32-bit signed integer hash code.
public virtual String ToString()
Summary: Returns a formatted string representation of this actor handle.
Returns:
- String: A string identifying the actor handle and its state.