Skip to main content

ObjectPrefab

Class

Represents reusable SceneObject hierarchy stored as a resource.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Index

Remarks

Can be instantiated through script or brought into the scene by dragging from Asset Browser to Scene Hierarchy panel.

Example

// Instantiate a prefab under a parent {@link SceneObject}
// @input Asset.ObjectPrefab prefab
// @input SceneObject parentObject
var newObject = script.prefab.instantiate(script.parentObject);
print("Prefab Instantiated: " + newObject.name);

Extends

Properties

name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

createFromSceneObject()

static createFromSceneObject(sceneObject): ObjectPrefab

Creates an ObjectPrefab based on the given SceneObject and it's children. That ObjectPrefab can then be instantiated. /

Parameters

ParameterType
sceneObjectSceneObject

Returns

ObjectPrefab

Since

Lens Scripting Version 344


getTypeName()

static getTypeName(): TypeName<ObjectPrefab>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<ObjectPrefab>

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Asset.getTypeName


instantiate()

instantiate(parent?): SceneObject

Creates and returns a new instance of this object hierarchy underneath the specified parent object. If parent is null, the object will be created with no parent.

Parameters

ParameterType
parent?SceneObject

Returns

SceneObject


instantiateAsync()

instantiateAsync(parent, onSuccess, onFailure, onProgress): void

Instantiate a prefab asynchronously.

Parameters

ParameterType
parentSceneObject
onSuccess(sceneObject) => void
onFailure(error) => void
onProgress(progress) => void

Returns

void


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Asset.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Asset.isSame

See also

Prefabs guide.