The class that represents an entity.

The Rhodonite Entity Class which are an entities that exists in space. Entities can acquire various functions by having components on themselves.

Hierarchy (view full)

Implements

Constructors

  • Creates a new Entity instance.

    Parameters

    • entityUID: number

      The unique identifier for this entity

    • isAlive: boolean

      Whether this entity is alive or not

    • Optionalcomponents: Map<number, Component>

      Optional map of existing components to initialize with

    Returns Entity

    When creating an Entity, use the createEntity method of the EntityRepository class instead of directly calling this constructor.

Properties

__components: Map<number, Component>

The Map of components. All components must be managed in this map

_isAlive: boolean

No use yet

_myLatestCopyEntityUID: number = Entity.invalidEntityUID
_tags: RnTags = {}

Collection of tags associated with this object

InvalidObjectUID: -1 = -1

Invalid object UID constant

currentMaxObjectCount: number = 0

Current maximum object count for UID generation

invalidEntityUID: -1 = -1

Invalid Entity UID constant value

Accessors

Methods

  • Destroys this entity and releases all associated resources.

    Returns void

    This method calls the destroy method on all components attached to this entity and marks the entity as no longer alive. After calling this method, the entity should not be used.

  • Internal

    Removes a component from this entity by its component type identifier.

    Parameters

    • componentTID: number

      The component type identifier of the component to remove

    Returns void

  • Internal

    Sets a component on this entity.

    Parameters

    • componentType: typeof Component

      The constructor/class of the component to set

    • component: Component

      The component instance to attach to this entity

    Returns void

    This method associates a component instance with this entity using the component's type ID. If a component of the same type already exists, it will be replaced.

  • Retrieves a component of the specified type from this entity.

    Parameters

    • componentType: typeof Component

      The constructor/class of the component to retrieve

    Returns undefined | Component

    The component instance if found, undefined if the entity doesn't have this component type

  • Retrieves a complete tag object (name and value) for the specified tag name

    Parameters

    • tagName: string

      The name of the tag to retrieve

    Returns Tag

    A Tag object containing the name and value

  • Checks whether this entity has a component of the specified type.

    Parameters

    • componentType: typeof Component

      The constructor/class of the component to check for

    Returns boolean

    True if the entity has a component of the specified type, false otherwise

  • Checks whether this object has a tag with the specified name

    Parameters

    • tagName: string

      The name of the tag to check for

    Returns boolean

    True if the tag exists (value is not null/undefined), false otherwise

  • Checks if this object has a tag with the specified name and value

    Parameters

    • tagName: string

      The tag name to match

    • tagValue: string

      The tag value to match

    Returns boolean

    True if the object has a matching tag, false otherwise

  • Checks if this object has all the specified tags with exactly matching values

    Parameters

    • tags: RnTags

      Object containing tag names as keys and expected values

    Returns boolean

    True if all specified tags exist with matching values, false otherwise

  • Checks if the object's combined tag string contains all the provided search strings. This allows for flexible searching within tag names and values.

    Parameters

    • stringArray: string[]

      Array of strings that must all be present in the combined tag string

    Returns boolean

    True if all strings are found in the combined tag string, false otherwise

  • Attempts to retrieve the AnimationStateComponent from this entity.

    Returns undefined | AnimationStateComponent

    The AnimationStateComponent if this entity has one, undefined otherwise

    This is a convenience method that provides type-safe access to the AnimationStateComponent without requiring explicit type casting.

  • Attempts to retrieve the CameraComponent from this entity.

    Returns undefined | CameraComponent

    The CameraComponent if this entity has one, undefined otherwise

    This is a convenience method that provides type-safe access to the CameraComponent without requiring explicit type casting.

  • Attempts to retrieve the ConstraintComponent from this entity.

    Returns undefined | ConstraintComponent

    The ConstraintComponent if this entity has one, undefined otherwise

    This is a convenience method that provides type-safe access to the ConstraintComponent without requiring explicit type casting.

  • Attempts to retrieve the LightComponent from this entity.

    Returns undefined | LightComponent

    The LightComponent if this entity has one, undefined otherwise

    This is a convenience method that provides type-safe access to the LightComponent without requiring explicit type casting.

  • Attempts to retrieve the MeshComponent from this entity.

    Returns undefined | MeshComponent

    The MeshComponent if this entity has one, undefined otherwise

    This is a convenience method that provides type-safe access to the MeshComponent without requiring explicit type casting.

  • Attempts to retrieve the PhysicsComponent from this entity.

    Returns undefined | PhysicsComponent

    The PhysicsComponent if this entity has one, undefined otherwise

    This is a convenience method that provides type-safe access to the PhysicsComponent without requiring explicit type casting.

  • Attempts to retrieve the VrmComponent from this entity.

    Returns undefined | VrmComponent

    The VrmComponent if this entity has one, undefined otherwise

    This is a convenience method that provides type-safe access to the VrmComponent without requiring explicit type casting.

  • Attempts to set a tag on this object. If the tag already exists, it will be replaced.

    Parameters

    • tag: Tag

      The tag object containing the name and value to set

    Returns boolean

    True if the tag was successfully set, false if the tag name contains invalid characters

  • Attempts to set a unique name for this object

    Parameters

    • name: string

      The desired unique name

    • toAddNameIfConflict: boolean

      If true, appends UID to make name unique when conflicts occur; if false, fails on conflict

    Returns boolean

    True if the name was successfully set, false if there was a conflict and toAddNameIfConflict was false

  • Retrieves an RnObject instance by its unique identifier

    Parameters

    • objectUid: number

      The unique identifier of the object to retrieve

    Returns undefined | RnObject

    The RnObject instance or undefined if not found or garbage collected

  • Searches for the first object that has a specific tag with the given value

    Parameters

    • tag: string

      The tag name to search for

    • value: string

      The tag value to match

    Returns undefined | WeakRef<RnObject>

    WeakRef to the first matching object, or undefined if not found