Skip to main content

Editor.Assets.ObjectPrefab

Class

Reusable object template that can be instantiated in scenes.

Index

Example

const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;
const assetManager = model.project.assetManager;

// Find all ObjectPrefab assets in the project
const prefabs = assetManager.assets.filter(
a => a.isOfType('ObjectPrefab')
) as Editor.Assets.ObjectPrefab[];

// Inspect each prefab's lazyLoading/retainAssets flags and instances
let totalInstances = 0;
for (const prefab of prefabs) {
totalInstances += prefab.prefabInstances.length;
}

console.log(`Total prefabs: ${prefabs.length}, total instances: ${totalInstances}`);

Extends

Properties

cacheFile

readonly cacheFile: Path

Path to the cached asset file.

Inherited from

ObjectOwner.cacheFile


fileMeta

readonly fileMeta: AssetImportMetadata

Import metadata for the asset.

Inherited from

ObjectOwner.fileMeta


id

readonly id: Uuid

The unique id of the entity.

Inherited from

ObjectOwner.id


lazyLoading

lazyLoading: boolean

Whether prefab assets load lazily on first use.


meta

readonly meta: Meta

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

Inherited from

ObjectOwner.meta


name

readonly name: string

The name of the asset.

Inherited from

ObjectOwner.name


prefabInstances

readonly prefabInstances: SceneObject[]

List of scene objects instantiated from this prefab.


retainAssets

retainAssets: boolean

Whether referenced assets are preserved when the prefab is modified.


rootSceneObjects

readonly rootSceneObjects: SceneObject[]

A list of scene objects which is a direct child of this entity.

Inherited from

ObjectOwner.rootSceneObjects


sceneObjects

readonly sceneObjects: SceneObject[]

A list of scene objects which is a child of this entity.

Inherited from

ObjectOwner.sceneObjects


type

readonly type: string

The entity's type.

Inherited from

ObjectOwner.type

Methods

addSceneObject()

addSceneObject(parent): SceneObject

Adds a scene object to the entity.

Parameters

ParameterType
parentSceneObject

Returns

SceneObject

Inherited from

ObjectOwner.addSceneObject


apply()

apply(): void

Applies edits made directly to the prefab asset's root object to the prefab and propagates them to all of its instances. Does nothing if the prefab has no root object.

Returns

void


createSceneObject()

createSceneObject(name): SceneObject

Creates a scene object to the entity.

Parameters

ParameterType
namestring

Returns

SceneObject

Inherited from

ObjectOwner.createSceneObject


findComponents()

findComponents(entityType): Component[]

Find components on the entity.

Parameters

ParameterType
entityTypestring

Returns

Component[]

Inherited from

ObjectOwner.findComponents


getDirectlyReferencedEntities()

getDirectlyReferencedEntities(): Entity[]

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

Returns

Entity[]

Inherited from

ObjectOwner.getDirectlyReferencedEntities


getMeta()

static getMeta(): Meta

Returns metadata about this type.

Returns

Meta

Inherited from

ObjectOwner.getMeta


getOwnedEntities()

getOwnedEntities(): Entity[]

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

Returns

Entity[]

Inherited from

ObjectOwner.getOwnedEntities


getRootObjectIndex()

getRootObjectIndex(object): number

Get the index of object within the list of all the root objects.

Parameters

ParameterType
objectSceneObject

Returns

number

Inherited from

ObjectOwner.getRootObjectIndex


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ObjectOwner.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ObjectOwner.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ObjectOwner.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

ObjectOwner.isSame


reparentSceneObject()

reparentSceneObject(object, newParent, position?): void

Reparent the scene object to another scene object. You can use this to reparent objects to the root (i.e. pass in null).

Parameters

ParameterType
objectSceneObject
newParentSceneObject
position?number

Returns

void

Inherited from

ObjectOwner.reparentSceneObject