Skip to main content

AnchorComponent

Class

The active tracker: set its AnchorModule.Anchor and it drives its SceneObject's transform, reporting per-frame tracking state.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported — Available on SPECS only
  • SPECSFully supported
  • Camera Kit WebNot supported — Available on SPECS only
  • Camera Kit MobileNot supported — Available on SPECS only

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not supported — Available on SPECS only.

Since Lens Scripting v376

The active tracker: set its AnchorModule.Anchor and it drives its SceneObject's transform, reporting per-frame tracking state. Add this Component to the SceneObject you want anchored, then assign an Anchor obtained from an AnchorModule.AnchorSession.

Index

Example

const tracker = script.getSceneObject().createComponent(AnchorComponent.getTypeName());
tracker.anchor = anchor; // an Anchor obtained from an AnchorSession
tracker.onStateChanged.add((state) => {
print("anchor tracking state: " + state);
});

Extends

Properties

anchor

anchor: Anchor

SPECS

The anchor this component tracks. Set it to begin tracking; clear it (null) to stop.

Since

Lens Scripting Version 376

Default Value

null
@snapOS

enabled

enabled: boolean

If disabled, the Component will stop enacting its behavior.

Default Value

true

Inherited from

Component.enabled


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
}

Inherited from

Component.isBeingDestroyed


isEnabledInHierarchy

readonly isEnabledInHierarchy: boolean

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

Inherited from

Component.isEnabledInHierarchy


onPositionalUncertaintyChanged

readonly onPositionalUncertaintyChanged: event1<number, void>

SPECS

Called when the anchor's positional uncertainty changes. Roughly how accurate the tracked position is, in centimeters (~1σ).

Since

Lens Scripting Version 376


onStateChanged

readonly onStateChanged: event1<AnchorTrackingState, void>

SPECS

Called when the anchor's tracking state changes (e.g. found or lost).

Since

Lens Scripting Version 376


sceneObject

readonly sceneObject: SceneObject

The SceneObject this component is on.

Inherited from

Component.sceneObject


state

readonly state: AnchorTrackingState

SPECS

Whether the anchor is currently being tracked.

Since

Lens Scripting Version 376


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Component.uniqueIdentifier

Methods

destroy()

destroy(): void

Destroys the component.

Returns

void

Inherited from

Component.destroy


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject

Inherited from

Component.getSceneObject


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform

Inherited from

Component.getTransform


getTypeName()

static getTypeName(): TypeName<AnchorComponent>

SPECS

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

Since

Lens Scripting Version 376

Overrides

Component.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

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

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

Component.isSame