Skip to main content

Component

Class

The base class for all components.

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

The base class for all components. Components are attached to SceneObject and add various behaviors to it.

Index

Remarks

For example, in the default scene, the Camera Object is a SceneObject which contains the Camera component to render the scene from the point of view of that object. You can add a DeviceTracking component onto the object, so that the Transform of that object is modified based on the device's movement.

Example

You can add a component to an object by selecting an object in the Scene Hierarchy panel, and pressing + Add Component in the Inspector panel; or through script:

const currentObject = script.sceneObject;
const newImageComponent = currentObject.createComponent(Image.getTypeName());

You can access components on an object directyly through script:

const currentObject = script.sceneObject;
const firstImageOnObject = currentObject.getComponent(Image.getTypeName());

or creating an input for it:

// @input Component.image passedInComponent
const imageComponent = script.passedInComponent;

Component classes can be a child of other classes. For example, you can get a ClothVisual and EyeColorVisual by asking for the parent MaterialMeshVisual.

// Get the first MaterialMeshVisual on the object
const someMaterialMeshVissual = currentObject.getComponent(MaterialMeshVisual.getTypeName());

// Confirm the type of visual that is needed
if(someMaterialMeshVissual.isOfType(ClothVisual.getTypeName())){
var mat = someMaterialMeshVissual.mainMaterial;
}

You can also write these scripts as TypeScript. Learn more in the TypeScript guide.

@component
export class somethingWithImage extends BaseScriptComponent {
@input
imageComponent: Component.Image;

onAwake() {
let imageComponent = this.imageComponent;
}
}

Extends

Extended by

Properties

enabled

enabled: boolean

If disabled, the Component will stop enacting its behavior.

Default Value

true

isBeingDestroyed

readonly isBeingDestroyed: boolean

Returns true if this Component is currently being destroyed. Becomes true as soon as destruction begins via Component#destroy or destruction of its owning SceneObject, before any OnDestroyEvent callbacks fire.

Since

Lens Scripting Version 364

Example

if (!script.isBeingDestroyed) {
// Component is still fully alive
}

isEnabledInHierarchy

readonly isEnabledInHierarchy: boolean

Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.


sceneObject

readonly sceneObject: SceneObject

The SceneObject this component is on.


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

SerializableWithUID.uniqueIdentifier

Methods

destroy()

destroy(): void

Destroys the component.

Returns

void


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform


getTypeName()

static getTypeName(): TypeName<Component>

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<Component>

Overrides

SerializableWithUID.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

SerializableWithUID.getTypeName


isOfType()

isOfType(type): boolean

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

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

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

SerializableWithUID.isSame

See also