Skip to main content

BasicScriptComponent

Base class for script components attached to SceneObjects.

TypeNameInterface Description
FunctionsgetSceneObject(): SceneObject

Function: Get the scene object this component is attached to.

Returns The scene object this component is attached to.

FunctionsonDestroy(): void

Function: Called by engine when component is destroyed.

FunctionsonDisable(): void

Function: Called by engine when component itself is disabled.

FunctionsonEnable(): void

Function: Called by engine when component itself is enabled.

FunctionsonEvent(event: IEvent): void

Function: Called by the runtime when a global event is dispatched. Only pre-registered event types are delivered here (AppEventType.COMPAT_BEF, EventType.DUAL_INSTANCE, EventType.SCENE_COMPONENTS_ADDED_OR_REMOVED). For other event types such as Touch or RecordStart, use EventManager.getGlobalEmitter().on() instead — it automatically subscribes to the native event type and is the recommended approach for all new code.

Parameters

event: - The event object.

FunctionsonInit(): void

Function: Called by engine when component is added to SceneObject, will be called even if component is disabled.

FunctionsonLateUpdate(deltaTime: number): void

Function: Called by engine every frame after all systems updated.

Parameters

deltaTime: - Time duration from last update in seconds.

FunctionsonStart(): void

Function: Called by engine when component is started, will not be called if component is disabled.

FunctionsonUpdate(deltaTime: number): void

Function: Called by engine every frame.

Parameters

deltaTime: - Time duration from last update in seconds.

Examples

onEvent(event: IEvent): void

// Recommended: use GlobalEmitter for Touch / Record events
export class MyScript extends APJS.BasicScriptComponent {
onStart() {
const emitter = APJS.EventManager.getGlobalEmitter();
emitter.on(APJS.EventType.Touch, this.onTouch, this);
}
onDestroy() {
const emitter = APJS.EventManager.getGlobalEmitter();
emitter.off(APJS.EventType.Touch, this.onTouch, this);
}
private onTouch(event: APJS.IEvent) {
const touch = event.args[0] as APJS.TouchData;
}
}

Use Case

Example 1 — Continuously rotate object around Y axis at a constant speed

@component()
export class ContinuousRotation extends APJS.BasicScriptComponent {
private rotationSpeed: number = 90;

onUpdate(deltaTime: number): void {
const transform = this.getSceneObject().getTransform();
const euler = transform.localEulerAngles;
transform.localEulerAngles = new APJS.Vector3f(
euler.x,
euler.y + this.rotationSpeed * deltaTime,
euler.z
);
}
}

Example 2 — Object fades in and out continuously (opacity animation)

@component()
export class FadeInOut extends APJS.BasicScriptComponent {
private elapsed: number = 0;
private speed: number = 1;

onUpdate(deltaTime: number): void {
this.elapsed += deltaTime;
const alpha = (Math.sin(this.elapsed * this.speed * Math.PI * 2) + 1) / 2;
const image = this.getSceneObject().getComponent("Image") as APJS.Image;
if (image) {
const c = image.color;
image.color = new APJS.Color(c.r, c.g, c.b, alpha);
}
}
}
Copyright © 2026 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalTerms of ServicePrivacy PolicyCookies