Component
ClassThe base class for all components.
- Available on all platforms
The base class for all components. Components are attached to SceneObject and add various behaviors to it.
Index
Properties
Methods
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
VisualVertexCacheSpriteAlignerSplineComponentSkinScreenTransformScreenRegionComponentPinToMeshComponentManipulateComponentLookAtComponentLightSourceInteractionComponentHintsComponentHeadEditorInteractionProfileCompositionLayerRenderComponentCompositionLayerComponentCanvasCameraBlendShapesAnimationPlayerAnimationMixerAnimationScriptComponentMarkerTrackingComponentColocatedTrackingComponentDeviceLocationTrackingComponentLocatedAtComponentCustomLocationGroupComponentAnchorComponentBlurNoiseEstimationRectangleSetterMLComponentColliderComponentConstraintComponentWorldComponentObjectTracking3DGyroscopeDeviceTrackingTrackedPointComponentObjectTrackingAudioEffectComponentAudioComponentAudioListenerComponent
Properties
enabled
enabled:
boolean
If disabled, the Component will stop enacting its behavior.
Default Value
true
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
}
isEnabledInHierarchy
readonlyisEnabledInHierarchy:boolean
Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.
sceneObject
readonlysceneObject:SceneObject
The SceneObject this component is on.
uniqueIdentifier
readonlyuniqueIdentifier: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
getTransform()
getTransform():
Transform
Returns the Transform this component is attached to.
Returns
getTypeName()
staticgetTypeName():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
| 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
See also
- Building Lenses Guide.
- Camera Overview Guide.