Adds entity as a child
The entity
Whether the child was added
Inserts entity as a child at specified index.
The entity
The index. If undefined the child will be added in the end.
Whether the child was added
The children entities. Warning: this creates a new array every time it's called.
The history object for this entity.
The observer object for this entity.
The parent entity.
The entity in the 3D viewport of the Editor.
Adds a component to this Entity
The component name
Default component data. Defaults values will be used for any missing fields. For details on component properties see Entity.
Adds a script to the script component of this entity. If a script component does not exist, this method will add the script component as well.
The name of the script.
Optional
attributes?: objectThe 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.
Optional
history?: booleanWhether to add a history action. Defaults to true.
Optional
index?: numberThe desired index in the entity's scripts order to add this script.
A promise
Deletes entity (and its children)
Optional
history?: booleanWhether to record a history action. Defaults to true.
A promise
Executes function for this entity and its children in depth first order.
A function that takes an entity as an argument
Duplicates entity under the same parent
Optional
history?: booleanWhether to record a history action. Defaults to true.
Optional
rename?: booleanWhether to rename the duplicated entity. Defaults to false.
Optional
select?: booleanWhether to select the new entity. Defaults to false.
The new entity
Finds first entity by name using depth-first search
The name
The entity
Gets value at path. See Entity for a list of properties.
The path
The value
Checks if path exists. See Entity for a list of properties.
The path
True if path exists
Inserts value in array at path, at specified index. See Entity for a list of properties.
The path
The value
Optional
index: numberThe index (if undefined the value will be inserted in the end)
Whether the value was inserted
Returns true if this entity is a descendant of the specified parent entity.
The parent
True if it is
Returns JSON representation of entity data
console.log(entity.json());
Finds all entities with specified tags
The tags. If multiple tags are specified then entities that contain ANY of the specified tags will be included. If an argument is an array of tags then entities that contain ALL of the tags in the array will be included.
The entities
// entities that have the following tag
const entities = editor.entities.root.listByTag('tag');
// entities that have any of the following tags
const entities = editor.entities.root.listByTag('tag', 'tag2');
// entities that have all of the following tags
const entities = editor.entities.root.listByTag(['tag', 'tag2']);
Removes a script from the entity's script component.
The name of the script.
Optional
history?: booleanWhether to record a history action. Defaults to true.
Remove value from array at path. See Entity for a list of properties.
The path
The value
Whether the value was removed
Reparents entity under new parent
The new parent
The desired index. If undefined the entity will be added at the end of the parent's children.
Optional
history?: booleanWhether to record a history action. Defaults to true.
Optional
preserveTransform?: booleanWhether to preserve the original transform after reparenting
Sets value at path. See Entity for a list of properties.
The path
The value
Whether the value was set
Unsets value at path. See Entity for a list of properties.
The path
Whether the value was unset
The Entity class represents an entity in the Editor.