ScriptComponent
ClassUsed to bind custom JavaScript or TypeScript code to specific Lens events for dynamic interactivity.
- Available on all platforms
Used to bind custom JavaScript or TypeScript code to specific Lens events for dynamic interactivity. Top level contents of a JS file will run as an OnAwakeEvent.
Index
Properties
Methods
Remarks
These Script Components are attached to SceneObjects, providing the ability to modify properties and behaviors of those objects or others within the scene. Script Components expose input fields in the Inspector panel, allowing for customization of script behavior without altering code. Any script can access the ScriptComponent executing them through the variable script.
Example
// Bind a function to the MouthOpened event
function onMouthOpen(eventData)
{
print("mouth was opened");
}
var event = script.createEvent("MouthOpenedEvent");
event.bind(onMouthOpen);
Extends
Indexable
[
index:string]:any
Properties
enabled
enabled:
boolean
If disabled, the Component will stop enacting its behavior.
Default Value
true
Inherited from
isBeingDestroyed
readonlyisBeingDestroyed: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
}
Inherited from
isEnabledInHierarchy
readonlyisEnabledInHierarchy:boolean
Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.
Inherited from
Component.isEnabledInHierarchy
sceneObject
readonlysceneObject:SceneObject
The SceneObject this component is on.
Inherited from
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
updateOrder
readonlyupdateOrder:number
The relative execution order of this script's lifecycle callbacks
(onStart, onUpdate, onLateUpdate, etc.) among all scripts in the Lens.
Scripts with a smaller updateOrder run before scripts with a larger
updateOrder. Reflects the updateOrder set on the attached
ScriptAsset. Defaults to 0.
Remarks
updateOrder only orders scripts relative to each other; it
does not affect ordering relative to non-script engine Components.
Since
Lens Scripting Version 367
Example
if (script.updateOrder < 0) {
// This script runs before scripts at the default updateOrder.
}
Methods
createEvent()
Call Signature
createEvent<
K>(eventType):EventNameMap[K]
Adds a new SceneEvent, triggered by eventType events, to the ScriptComponent.
Type Parameters
| Type Parameter |
|---|
K extends keyof EventNameMap |
Parameters
| Parameter | Type |
|---|---|
eventType | K |
Returns
EventNameMap[K]
Call Signature
createEvent<
T>(eventType):T
Adds a new SceneEvent, triggered by eventType events, to the ScriptComponent.
Type Parameters
| Type Parameter |
|---|
T extends SceneEvent |
Parameters
| Parameter | Type |
|---|---|
eventType | TypeName<T> |
Returns
T
destroy()
destroy():
void
Destroys the component.
Returns
void
Inherited from
getReferencedEvents()
getReferencedEvents():
SceneEvent[]
Returns the list of SceneEvents referenced by this ScriptComponent.
Returns
Since
Lens Scripting Version 354
getSceneObject()
getSceneObject():
SceneObject
Returns the SceneObject the component is attached to.
Returns
Inherited from
getTransform()
getTransform():
Transform
Returns the Transform this component is attached to.
Returns
Inherited from
getTypeName()
staticgetTypeName():TypeName<ScriptComponent>
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<ScriptComponent>
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
removeEvent()
removeEvent(
event?):void
Removes a previously added SceneEvent from the ScriptComponent.
Parameters
| Parameter | Type |
|---|---|
event? | SceneEvent |
Returns
void
requestPersistInput()
requestPersistInput(
inputName):void
Requests Lens Studio to persist the named @input into the project model.
Only has effect in the Scene Editor viewport.
Call after mutating the input from script when the change should persist. Will only persist if this ScriptComponent is still alive at the end of the frame.
Parameters
| Parameter | Type |
|---|---|
inputName | string |
Returns
void
Since
Lens Scripting Version 378
Example
script.topLeft = handle.getTransform().getLocalPosition();
script.requestPersistInput("topLeft");