Base class for objects in Needle Engine. Extends Object3D from three.js. GameObjects can have components attached to them, which can be used to add functionality to the object. They manage their components and provide methods to add, remove and get components.

All Object3D types loaded in Needle Engine have methods like addComponent. These methods are available directly on the GameObject instance:

target.addComponent(MyComponent);

And can be called statically on the GameObject class as well:

GameObject.setActive(target, true);

Hierarchy

Implements

Constructors

Properties

activeSelf: boolean

Indicates if the GameObject is currently active. Inactive GameObjects will not be rendered or updated. When the activeSelf state changes, components will receive Component.onEnable or Component.onDisable callbacks.

guid: undefined | string

Unique identifier for this GameObject

hideFlags: HideFlags

Allows to control e.g. if an object should be exported

Accessors

  • get worldForward(): Vector3

    The forward direction vector of this GameObject in world space

    Returns Vector3

  • get worldPosition(): Vector3

    The position of this GameObject in world space

    Returns Vector3

  • set worldPosition(val: Vector3): void

    Get or set the world position of the Object3D.
    Added by Needle Engine.

    Parameters

    Returns void

  • get worldQuaternion(): Quaternion

    Get or set the world quaternion of the Object3D.
    Added by Needle Engine.

    Returns Quaternion

  • set worldQuaternion(val: Quaternion): void

    The rotation of this GameObject in world space as a quaternion

    Parameters

    Returns void

  • get worldRight(): Vector3

    The right direction vector of this GameObject in world space

    Returns Vector3

  • get worldRotation(): Vector3

    Get or set the world rotation of the Object3D.
    Added by Needle Engine.

    Returns Vector3

  • set worldRotation(val: Vector3): void

    The rotation of this GameObject in world space in euler angles (degrees)

    Parameters

    Returns void

  • get worldScale(): Vector3

    Get or set the world scale of the Object3D.
    Added by Needle Engine.

    Returns Vector3

  • set worldScale(val: Vector3): void

    The scale of this GameObject in world space

    Parameters

    Returns void

  • get worldUp(): Vector3

    The up direction vector of this GameObject in world space

    Returns Vector3

Methods

  • Creates a new component on this gameObject or adds an existing component instance

    Type Parameters

    Parameters

    • comp: T | ConstructorConcrete<T>

      Component type constructor or existing component instance

    • Optionalinit: Partial<
          NoInternalNeedleEngineState<
              FilterStartingWith<FilterTypes<T, undefined | null | Function>, "_">,
          >,
      >

      Optional initialization values for the component

    Returns T

    The newly created or added component

  • Type Parameters

    Parameters

    • type: ConstructorConcrete<T>
    • Optionalinit: Partial<
          NoInternalNeedleEngineState<
              FilterStartingWith<FilterTypes<T, undefined | null | Function>, "_">,
          >,
      >

    Returns T

    Use addComponent instead

  • Destroys this GameObject and all its components. Internally, this is added to the three.js Object3D prototype.

    Returns any

  • Gets a component of the specified type attached to this GameObject

    Type Parameters

    • T

    Parameters

    • type: Constructor<T>

      Constructor of the component type to get

    Returns null | T

    The component if found, otherwise null

  • Gets a component of the specified type in this GameObject's children hierarchy

    Type Parameters

    • T

    Parameters

    • type: Constructor<T>

      Constructor of the component type to get

    Returns null | T

    The first matching component if found, otherwise null

  • Gets a component of the specified type in this GameObject's parent hierarchy

    Type Parameters

    • T

    Parameters

    • type: Constructor<T>

      Constructor of the component type to get

    Returns null | T

    The first matching component if found, otherwise null

  • Gets all components of the specified type attached to this GameObject

    Type Parameters

    • T

    Parameters

    • type: Constructor<T>

      Constructor of the component type to get

    • Optionalarr: T[]

      Optional array to populate with the components

    Returns T[]

    Array of components

  • Gets all components of the specified type in this GameObject's children hierarchy

    Type Parameters

    • T

    Parameters

    • type: Constructor<T>

      Constructor of the component type to get

    • Optionalarr: T[]

      Optional array to populate with the components

    Returns T[]

    Array of components

  • Gets all components of the specified type in this GameObject's parent hierarchy

    Type Parameters

    • T

    Parameters

    • type: Constructor<T>

      Constructor of the component type to get

    • Optionalarr: T[]

      Optional array to populate with the components

    Returns T[]

    Array of components

  • Gets an existing component of the specified type or adds a new one if it doesn't exist

    Type Parameters

    • T

    Parameters

    • typeName: null | ConstructorConcrete<T>

      Constructor of the component type to get or add

    Returns T

    The existing or newly added component

  • Removes a component from this GameObject

    Type Parameters

    Parameters

    • comp: T

      Component instance to remove

    Returns T

    The removed component

  • Adds an object to parent and ensures all components are properly registered

    Parameters

    • instance: undefined | null | Object3D<Object3DEventMap>

      Object to add

    • parent: Object3D

      Parent to add the object to

    • Optionalcontext: Context

      Optional context to use

    Returns void

  • Adds a new component (or moves an existing component) to the provided object

    Type Parameters

    Parameters

    • go: Object3D<Object3DEventMap> | IGameObject

      Object to add the component to

    • instanceOrType: T | ConstructorConcrete<T>

      If an instance is provided it will be moved to the new object, if a type is provided a new instance will be created

    • Optionalinit: Partial<
          NoInternalNeedleEngineState<
              FilterStartingWith<FilterTypes<T, undefined | null | Function>, "_">,
          >,
      >

      Optional init object to initialize the component with

    • Optionalopts: { callAwake: boolean }

      Optional options for adding the component

    Returns T

    The added or moved component

  • Type Parameters

    Parameters

    • go: Object3D<Object3DEventMap> | IGameObject
    • type: T | ConstructorConcrete<T>
    • Optionalinit: Partial<
          NoInternalNeedleEngineState<
              FilterStartingWith<FilterTypes<T, undefined | null | Function>, "_">,
          >,
      >
    • callAwake: boolean = true

    Returns T

    use addComponent

  • Destroys an object

    Parameters

    • instance: Object3D<Object3DEventMap> | Behaviour

      Object to destroy

    • recursive: boolean = true

      If true, all children will be destroyed as well. Default: true

    Returns void

  • Destroys an object on all connected clients (if in a networked session)

    Parameters

    • instance: Object3D<Object3DEventMap> | Behaviour

      Object to destroy

    • Optionalcontext: Context

      Optional context to use

    • recursive: boolean = true

      If true, all children will be destroyed as well

    Returns void

  • Finds an object or component by its unique identifier

    Parameters

    • guid: string

      Unique identifier to search for

    • hierarchy: Object3D

      Root object to search in

    Returns undefined | null | Behaviour | GameObject

    The found GameObject or Component, or null/undefined if not found

  • Finds the first object of the specified component type in the scene

    Type Parameters

    Parameters

    • typeName: Constructor<T>

      Constructor of the component type

    • Optionalcontext: Object3D<Object3DEventMap> | Context

      Context or root object to search in

    • includeInactive: boolean = true

      Whether to include inactive objects in the search

    Returns null | T

    The first matching component if found, otherwise null

  • Finds all objects of the specified component type in the scene

    Type Parameters

    Parameters

    • typeName: Constructor<T>

      Constructor of the component type

    • Optionalcontext: Object3D<Object3DEventMap> | Context

      Context or root object to search in

    Returns T[]

    Array of matching components

  • Executes a callback for all components of the provided type on the provided object and its children

    Parameters

    • instance: Object3D

      Object to run the method on

    • cb: (comp: Behaviour) => any

      Callback to run on each component, "return undefined;" to continue and "return ;" to break the loop

    • recursive: boolean = true

      If true, the method will be run on all children as well

    Returns any

    The last return value of the callback

  • Gets a component on the provided object

    Type Parameters

    Parameters

    • go: null | Object3D<Object3DEventMap> | IGameObject

      GameObject to get the component from

    • typeName: null | Constructor<T>

      Constructor of the component type

    Returns null | T

    The component if found, otherwise null

  • Gets a component of the specified type in the gameObject's children hierarchy

    Type Parameters

    Parameters

    • go: Object3D<Object3DEventMap> | IGameObject

      GameObject to search in

    • typeName: Constructor<T>

      Constructor of the component type

    Returns null | T

    The first matching component if found, otherwise null

  • Gets a component of the specified type in the gameObject's parent hierarchy

    Type Parameters

    Parameters

    • go: Object3D<Object3DEventMap> | IGameObject

      GameObject to search in

    • typeName: Constructor<T>

      Constructor of the component type

    Returns null | T

    The first matching component if found, otherwise null

  • Gets all components of the specified type on the provided object

    Type Parameters

    Parameters

    • go: null | Object3D<Object3DEventMap> | IGameObject

      GameObject to get the components from

    • typeName: Constructor<T>

      Constructor of the component type

    • arr: null | T[] = null

      Optional array to populate with the components

    Returns T[]

    Array of components

  • Gets all components of the specified type in the gameObject's children hierarchy

    Type Parameters

    Parameters

    • go: Object3D<Object3DEventMap> | IGameObject

      GameObject to search in

    • typeName: Constructor<T>

      Constructor of the component type

    • arr: null | T[] = null

      Optional array to populate with the components

    Returns T[]

    Array of components

  • Gets all components of the specified type in the gameObject's parent hierarchy

    Type Parameters

    Parameters

    • go: Object3D<Object3DEventMap> | IGameObject

      GameObject to search in

    • typeName: Constructor<T>

      Constructor of the component type

    • arr: null | T[] = null

      Optional array to populate with the components

    Returns T[]

    Array of components

  • Gets or adds a component of the specified type

    Type Parameters

    Parameters

    • go: Object3D<Object3DEventMap> | IGameObject

      GameObject to get or add the component to

    • typeName: ConstructorConcrete<T>

      Constructor of the component type

    Returns T

    The existing or newly added component

  • Creates a new instance of the provided object (like cloning it including all components and children)

    Parameters

    • instance: AssetReference

      Object to instantiate

    • Optionalopts: null | IInstantiateOptions

      Options for the instantiation (e.g. with what parent, position, etc.)

    Returns Promise<null | Object3D<Object3DEventMap>>

    The newly created instance

  • Creates a new instance of the provided object (like cloning it including all components and children)

    Parameters

    • instance: Object3D<Object3DEventMap> | GameObject

      Object to instantiate

    • Optionalopts: null | IInstantiateOptions

      Options for the instantiation (e.g. with what parent, position, etc.)

    Returns GameObject

    The newly created instance

  • Invokes a method on all components that have a method matching the provided name

    Parameters

    • go: undefined | null | Object3D<Object3DEventMap>

      GameObject to invoke the method on

    • functionName: string

      Name of the method to invoke

    • children: boolean = false

      Whether to invoke on children as well

    • ...args: any

      Arguments to pass to the method

    Returns void

  • Invokes a method on all components including children (if a method with that name exists)

    Parameters

    • go: undefined | null | Object3D<Object3DEventMap>

      GameObject to invoke the method on

    • functionName: string

      Name of the method to invoke

    • ...args: any

      Arguments to pass to the method

    Returns void

  • Checks if the GameObject is active in the hierarchy (e.g. if any parent is invisible or not in the scene it will be false)

    Parameters

    Returns boolean

    True if the GameObject is active in the hierarchy

  • Checks if the GameObject itself is active (same as go.visible)

    Parameters

    Returns boolean

    True if the GameObject is active

  • Checks if a GameObject has been destroyed

    Parameters

    Returns boolean

    True if the GameObject has been destroyed

  • Checks if a GameObject is using instanced rendering

    Parameters

    • instance: Object3D

      The GameObject to check

    Returns boolean

    True if the GameObject is using instanced rendering

  • Iterates through all components on the gameObject

    Parameters

    Returns Generator<any, void, unknown>

    Generator yielding each component

  • Marks a GameObject to be rendered using instancing

    Parameters

    • go: Object3D

      The GameObject to mark

    • instanced: boolean

      Whether the GameObject should use instanced rendering

    Returns void

  • Moves a component to a new object

    Type Parameters

    Parameters

    • go: Object3D<Object3DEventMap> | IGameObject

      GameObject to move the component to

    • instance: T | ConstructorConcrete<T>

      Component to move

    Returns T

    The moved component

  • Removes the object from its parent and deactivates all of its components

    Parameters

    • instance: undefined | null | Object3D<Object3DEventMap>

      Object to remove

    Returns void

  • Removes a component from its object

    Type Parameters

    Parameters

    • instance: T

      Component to remove

    Returns T

    The removed component

  • Sets the active state of a GameObject

    Parameters

    • go: Object3D

      The GameObject to modify

    • active: boolean

      Whether the GameObject should be active

    • processStart: boolean = true

      Whether to process the start callbacks if being activated

    Returns void

MMNEPVFCICPMFPCPTTAAATR