• Creates a copy (clone) of a GameObject or loads and instantiates an AssetReference. All components on the original object are cloned and awake() is called on them.

    Parameters

    • instance: AssetReference

      The Object3D to clone, or an AssetReference to load and instantiate

    • Optionalopts: null | IInstantiateOptions

      Optional instantiation settings (position, rotation, scale, parent)

    Returns Promise<null | Object3D<Object3DEventMap>>

    The cloned GameObject, or a Promise if instantiating from AssetReference

    import { instantiate } from "@needle-tools/engine";
    const clone = instantiate(original);
    clone.position.set(1, 0, 0);
    this.context.scene.add(clone);
    const clone = instantiate(original, {
    parent: parentObject,
    position: new Vector3(0, 1, 0),
    rotation: new Quaternion()
    });
    const instance = await instantiate(myAssetRef);
    if (instance) this.context.scene.add(instance);
    • GameObject.instantiate for the static method equivalent
    • destroy to remove instantiated objects
  • Creates a copy (clone) of a GameObject or loads and instantiates an AssetReference. All components on the original object are cloned and awake() is called on them.

    Parameters

    • instance: Object3D<Object3DEventMap> | IGameObject

      The Object3D to clone, or an AssetReference to load and instantiate

    • Optionalopts: null | IInstantiateOptions

      Optional instantiation settings (position, rotation, scale, parent)

    Returns IGameObject

    The cloned GameObject, or a Promise if instantiating from AssetReference

    import { instantiate } from "@needle-tools/engine";
    const clone = instantiate(original);
    clone.position.set(1, 0, 0);
    this.context.scene.add(clone);
    const clone = instantiate(original, {
    parent: parentObject,
    position: new Vector3(0, 1, 0),
    rotation: new Quaternion()
    });
    const instance = await instantiate(myAssetRef);
    if (instance) this.context.scene.add(instance);
    • GameObject.instantiate for the static method equivalent
    • destroy to remove instantiated objects