Skip to main content

Editor.Model.SceneObject

Class

A node in the scene hierarchy, holding components and child scene objects.

Index

Example

const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;
const scene = model.project.scene;
const rootObjects = scene.rootSceneObjects;

console.log(`Root scene objects: ${rootObjects.length}`);

for (const obj of rootObjects) {
console.log(`Object: "${obj.name}", enabled: ${obj.enabled}`);
console.log(` Children: ${obj.getChildrenCount()}`);
console.log(` Components: ${obj.getComponentsCount()}`);
console.log(` Has visuals: ${obj.hasVisuals}`);

const transform = obj.localTransform;
console.log(` Local position: ${transform.position}`);
console.log(` Local rotation: ${transform.rotation}`);
console.log(` Local scale: ${transform.scale}`);

const children = obj.children;
for (const child of children) {
console.log(` Child: "${child.name}"`);
}

const components = obj.components;
for (const comp of components) {
console.log(` Component type: ${comp.type}`);
}
}

if (rootObjects.length === 0) {
console.log('No root scene objects found in the scene.');
}

Extends

Properties

children

children: SceneObject[]

A list of scene objects that is a child of this scene object.


components

components: Component[]

A list of components that is a child of this scene object.


enabled

enabled: boolean

Whether this scene object is enabled or disabled.


hasPrefabChanges

readonly hasPrefabChanges: boolean

Whether this entity differs from its counterpart in the prefab or was added to the prefab instance. Always false outside prefab instances.

Inherited from

Prefabable.hasPrefabChanges


hasVisuals

readonly hasVisuals: boolean

Whether this scene object contains any component which is of type Editor.Components.Visual.


id

readonly id: Uuid

The unique id of the entity.

Inherited from

Prefabable.id


isPrefabInstanceRoot

readonly isPrefabInstanceRoot: boolean

Whether this entity is the root of a prefab instance.

Inherited from

Prefabable.isPrefabInstanceRoot


isPrefabPrototypeRoot

readonly isPrefabPrototypeRoot: boolean

Whether this object is the root object stored inside a prefab asset, rather than an instance in a scene.


layers

layers: LayerSet

The layerSet this scene object is on.


localTransform

localTransform: TransformEntity

The transform of this scene object relative to its parent.


meta

readonly meta: Meta

Metadata associated with this entity, providing access to its unique identifier and other descriptive properties.

Inherited from

Prefabable.meta


name

name: string

The name of the scene object.


topOwner

readonly topOwner: ObjectOwner

The root owner object at the top of this object's ownership chain.


type

readonly type: string

The entity's type.

Inherited from

Prefabable.type


worldTransform

worldTransform: WorldTransformAccessor

The transform of this scene object relative to the scene its in.

Methods

addChildAt()

addChildAt(value, pos?): void

Add a scene object as a child of this object at a specified pos.

Parameters

ParameterType
valueSceneObject
pos?number

Returns

void


addComponent()

addComponent<K>(componentType): ComponentNameMap[K]

Add a new Editor.Components.Component by componentType to this object.

Type Parameters

Type Parameter
K extends keyof ComponentNameMap

Parameters

ParameterType
componentTypeK

Returns

ComponentNameMap[K]


addComponentAt()

addComponentAt(value, pos?): void

Add the component value at the specified pos.

Parameters

ParameterType
valueComponent
pos?number

Returns

void


applyToPrefab()

applyToPrefab(): void

Apply the changes in this object's prefab instance to the prefab asset, which propagates them to its other instances. Logs a warning and does nothing if the object is not in an editable prefab instance.

Returns

void


clearChildren()

clearChildren(): void

Remove all children from this object.

Returns

void


clearComponents()

clearComponents(): void

Remove all components from this scene object.

Returns

void


commonParent()

static commonParent(sceneObjects): SceneObject

Returns the nearest common ancestor shared by a set of scene objects.

Parameters

ParameterType
sceneObjectsSceneObject[]

Returns

SceneObject


copy()

copy(): SceneObject

Returns a deep copy of this scene object, including its children and components.

Returns

SceneObject


destroy()

destroy(): void

Destroy this scene object. All references to it becomes invalid.

Returns

void


getChildAt()

getChildAt(pos): SceneObject

Get a specific object at the specified pos.

Parameters

ParameterType
posnumber

Returns

SceneObject


getChildrenCount()

getChildrenCount(): number

Get the number of children on this object.

Returns

number


getComponent()

getComponent<K>(componentType): ComponentNameMap[K]

Get the first component of componentType.

Type Parameters

Type Parameter
K extends keyof ComponentNameMap

Parameters

ParameterType
componentTypeK

Returns

ComponentNameMap[K]


getComponentAt()

getComponentAt(pos): Component

Get the component at the specified pos.

Parameters

ParameterType
posnumber

Returns

Component


getComponents()

getComponents<K>(componentType): ComponentNameMap[K][]

Get all the components of componentType on this object.

Type Parameters

Type Parameter
K extends keyof ComponentNameMap

Parameters

ParameterType
componentTypeK

Returns

ComponentNameMap[K][]


getComponentsCount()

getComponentsCount(): number

Get the number of components on this object.

Returns

number


getDirectlyReferencedEntities()

getDirectlyReferencedEntities(): Entity[]

A list of entities which this entity has a reference to.

Returns

Entity[]

Inherited from

Prefabable.getDirectlyReferencedEntities


getMeta()

static getMeta(): Meta

Returns metadata about this type.

Returns

Meta

Inherited from

Prefabable.getMeta


getOwnedEntities()

getOwnedEntities(): Entity[]

A list of entities which has a reference to this entity.

Returns

Entity[]

Inherited from

Prefabable.getOwnedEntities


getParent()

getParent(): SceneObject

Get the parent of this scene object.

Returns

SceneObject


getPrefabInstanceRoot()

getPrefabInstanceRoot(): Prefabable

Returns the nearest prefab instance root that contains this entity, starting with the entity itself, or null if it is not part of a prefab instance.

Returns

Prefabable

Inherited from

Prefabable.getPrefabInstanceRoot


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

Prefabable.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Prefabable.getTypeName


indexOfChild()

indexOfChild(value): number

Get the position of a specific object, if the object is a child of this object.

Parameters

ParameterType
valueSceneObject

Returns

number


indexOfComponent()

indexOfComponent(value): number

Get the position of a specific component value on this object.

Parameters

ParameterType
valueComponent

Returns

number


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Prefabable.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Prefabable.isSame


moveChild()

moveChild(child, destination): void

Move child in the order of children on this object.

Parameters

ParameterType
childSceneObject
destinationnumber

Returns

void


moveComponent()

moveComponent(origin, destination): void

Move the component value to a specified pos.

Parameters

ParameterType
originnumber
destinationnumber

Returns

void


removeChild()

removeChild(child): void

Remove a child from this from this scene object.

Parameters

ParameterType
childSceneObject

Returns

void


removeChildAt()

removeChildAt(pos): void

Remove a child at the specified pos.

Parameters

ParameterType
posnumber

Returns

void


removeComponent()

removeComponent(componentType): boolean

Remove the first component of componentType from this object.

Parameters

ParameterType
componentTypestring

Returns

boolean


removeComponentAt()

removeComponentAt(pos): void

Remove the components at the specified pos.

Parameters

ParameterType
posnumber

Returns

void


resetFromPrefab()

resetFromPrefab(): void

Discard the changes in this object's prefab instance so it matches the prefab asset again. Logs a warning and does nothing if the object is not in an editable prefab instance.

Returns

void


setChildAt()

setChildAt(pos, value): void

Set the child scene object value to be at the specified pos.

Parameters

ParameterType
posnumber
valueSceneObject

Returns

void


setComponentAt()

setComponentAt(pos, value): void

Set the component value to be at the specified pos.

Parameters

ParameterType
posnumber
valueComponent

Returns

void


setParent()

setParent(newParent, position?): void

Set the parent of this scene object.

Parameters

ParameterType
newParentSceneObject
position?number

Returns

void


staticMeta()

static staticMeta(): Meta

Returns the static metadata descriptor for the SceneObject type.

Returns

Meta


topLevel()

static topLevel(sceneObjects): SceneObject[]

Returns the topmost ancestor of this object in the scene hierarchy.

Parameters

ParameterType
sceneObjectsSceneObject[]

Returns

SceneObject[]


unlinkFromPrefab()

unlinkFromPrefab(): void

Disconnect this prefab instance root from its prefab asset so it becomes a regular scene object. Logs a warning and does nothing if the object is not a prefab instance root that can be unlinked.

Returns

void