EntityTemplate

Class used in preparation of instantiating an Entity. Attach components to your EntityTemplate object and instantiate it with instantiateEntity. You can instantiate multiple entities from the same EntityTemplate.

Constructor

new EntityTemplate()

Methods

attachComponent(componentType, componentValueopt) → {EntityTemplate}

Attach component to the entity template. If component is already attached, overwrite the component's specified attributes.

This will attach the component and all the component's dependencies if the dependencies aren't already attached. You can see the dependencies of each component in this page.

Parameters:
NameTypeAttributesDescription
componentTypestring

Component type

componentValueobject<optional>

Component value. The component attributes that are not specified will be given default values

Returns:
  • Returns this EntityTemplate object. Allows chaining of attachComponent.
Type: 
EntityTemplate
Example
const entityTemplate = new SDK3DVerse.EntityTemplate();
// Attach component and its dependencies (local_transform is a dependency of mesh_ref)
entityTemplate.attachComponent('mesh_ref', { value : meshUUID });
// Overwrite already attached components by attaching them again
entityTemplate.attachComponent('local_transform', { position : [1, 0, 0]});
// Chain attachComponent
entityTemplate.attachComponent('box_geometry').attachComponent('physics_material').attachComponent('rigid_body');

attachEntityComponents(entity) → {EntityTemplate}

Attach all components of an entity to the entity template with their values. If component is already attached, overwrite the component's specified attributes.

Parameters:
NameTypeDescription
entityEntity

Entity to attach components from

Returns:
  • Returns this EntityTemplate object. Allows chaining of attachComponent.
Type: 
EntityTemplate

(async) instantiateEntity(nameopt, parentopt) → {Entity}

Instantiate an Entity in the scene.

The entity will have the entity template's components attached. Some system components, such as debug_name, euid, local_aabb, and lineage, will be automatically attached as well.

Parameters:
NameTypeAttributesDefaultDescription
namestring<optional>
'unnamed entity'

The entity's name that will be set in its debug_name component

parentEntity<optional>
null

The parent of the entity. If null, the entity will be instantiated at the root

Returns:
  • Entity that was instantiated.
Type: 
Entity

(async) instantiateTransientEntity(nameopt, parentopt, deleteOnClientDisconnectionopt) → {Entity}

Instantiate a transient Entity in the scene. Transient entities only exist for the duration of the session.

The entity will have the entity template's components attached. Some system components, such as debug_name, euid, local_aabb, and lineage, will be automatically attached as well.

Parameters:
NameTypeAttributesDefaultDescription
namestring<optional>
'unnamed entity'

The entity's name that will be set in its debug_name component

parentEntity<optional>
null

The parent of the entity. If null, the entity will be instantiated at the root

deleteOnClientDisconnectionboolean<optional>
false

If true, entity will be deleted when the client that instantiated it disconnects from the session. If false, entity will be deleted when the session terminates, i.e. once all clients disconnect

Returns:
  • Transient entity that was instantiated.
Type: 
Entity

isAttached(componentType) → {boolean}

Return true if the specified component is attached to the entity template.

Parameters:
NameTypeDescription
componentTypestring

Component type

Returns:

Attached component state.

Type: 
boolean