The entities editor API

Hierarchy

  • Events
    • Entities

Internal

  • Removes entity from the list

    Parameters

    • entity: Entity

      The entity

    • entityReferences: object = null

      A map of entity references to nullify when this entity is removed

    Returns void

Other

  • Like Entity.addScript but works on multiple entities using a single history action.

    Parameters

    • entities: Entity[]

      The entities.

    • scriptName: string

      The name of the script.

    • options: { attributes: object; history: boolean; index: number } = {}

      Options

      • attributes: object

        The values of attributes. Each key is the name of the attributes and each value is the value for that attribute. Leave undefined to let the Editor set default values depending on the attribute types.

      • history: boolean

        Whether to add a history action. Defaults to true.

      • index: number

        The desired index in the entity's scripts order to add this script.

    Returns Promise<any>

    A promise

  • Creates new entity and adds it to the hierarchy

    Parameters

    • data: CreateEntityArguments = null

      Initial data for the entity

    • options: { history: boolean; index: number; select: boolean } = {}

      Options

      • history: boolean

        Whether to record a history action. Defaults to true.

      • index: number

        The child index that this entity will have under its parent.

      • select: boolean

        Whether to select new Entity. Defaults to false.

    Returns Entity

    The new entity

    const root = editor.entities.create({
    name: 'parent',
    });

    const child = editor.entities.create({
    name: 'child',
    parent: root,
    });
  • Delete specified entities

    Parameters

    • entities: Entity | Entity[]

      The entities

    • options: { history: boolean } = {}

      Options

      • history: boolean

        Whether to record a history action. Defaults to true.

    Returns Promise<void>

    await editor.entities.delete([entity1, entity2]);
    
  • Duplicates the specified entities under the same parent

    Parameters

    • entities: Entity[]

      The entities

    • Optionaloptions: { history?: boolean; rename?: boolean; select?: boolean } = {}

      Options

      • Optionalhistory?: boolean

        Whether to record a history action. Defaults to true.

      • Optionalrename?: boolean

        Whether to rename the duplicated entities. Defaults to false.

      • Optionalselect?: boolean

        Whether to select the new entities. Defaults to false.

    Returns Promise<Entity[]>

    The duplicated entities

    const duplicated = await editor.entities.duplicate(entities);
    
  • Paste entities copied into clipboard under the specified parent.

    Parameters

    • parent: Entity

      The parent

    • options: { history: boolean } = {}

      Options

      • history: boolean

        Whether to record a history action. Defaults to true.

    Returns Promise<Entity[]>

    The new entities

  • Like Entity.removeScript but works on multiple entities using a single history action.

    Parameters

    • entities: Entity[]

      The entities.

    • scriptName: string

      The name of the script.

    • options: { history: boolean } = {}

      Options

      • history: boolean

        Whether to record a history action. Defaults to true.

    Returns void

  • Reparents entities under new parent.

    Parameters

    • data: ReparentArguments[]

      The reparenting data

    • options: { history: boolean; preserveTransform: boolean } = {}

      Options

      • history: boolean

        Whether to record history. Defaults to true

      • preserveTransform: boolean

        Whether to preserve the transform of the entities. Defaults to false.

    Returns void

    const child = editor.entities.create();
    const parent = editor.entities.create();
    editor.entities.reparent([{
    entity: child,
    parent: parent
    }])
  • Waits for specified entity ids to be added to the scene. Once they are the callback is called with the entities as its argument.

    Parameters

    • entityIds: string[]

      The ids of the entities to wait for

    • timeoutMs: number

      Number of ms to wait before stopping to wait

    • callback: Function

      The callback to call when all entities have been added. The signature is (Entity[]) => void.

    Returns Function

    Returns a cancel function which can be called to cancel calling the callback when the entities are added.