Skip to main content

SceneObject

SceneObject is the base class for all SceneObjects in Scenes.

TypeNameInterface Description
Variablesenabled: boolean

Function: The enabled status of the SceneObject itself.

Variableslayer: number

Function: Layers can be used for selective rendering from cameras.

Variablesparent: SceneObject | null

Function: The parent of the scene object. <br/> Changing the parent will modify the parent-relative position, <br/> scale and rotation but keep the world space position, rotation and scale the same.

Variablesscene: Scene

Function: The scene to which this scene object belongs.

Functionsconstructor()

FunctionsaddComponent(type: string): Component | null

Function: Adds a component of the specified type to the scene object. The type string should use the public APJS component name.

Parameters

type: - The type of component to add.

Returns The added component, or null if the component could not be added.

Functionsclone(): SceneObject

Function: Clones the scene object.

Returns A cloned scene object.

FunctionsgetChild(name: string): SceneObject | null

Function: Finds a child by name and returns it. This lookup uses the child object name and returns the first matching child found by the underlying scene query.

Parameters

name: - The name of the sceneObject to find.

Returns The found child SceneObject, or null if no child with matching name is found.

FunctionsgetChildren(): SceneObject[]

Function: Gets all children scene objects of the scene object.

Returns An array of child SceneObjects.

FunctionsgetComponent(type: string): Component | null

Function: Gets a component of the specified type from the scene object. The type string should use the public APJS component name.

Parameters

type: The type of component to get.

Returns The component of the specified type, or null if not found.

FunctionsgetComponents(type?: string): Component[]

Function: Gets all components of the specified type from the scene object. When provided, the type string should use the public APJS component name.

Parameters

type: - Optional the type of components to get.

Returns An array of components of the specified type or all components for no type input.

FunctionsgetComponentsRecursive(type: string): Component[]

Function: Gets components of the specified type from this scene object and its descendants. The type string should use the public APJS component name.

Parameters

type: - Component type name.

Returns Matching components from the hierarchy.

FunctionsgetTransform(): Transform

Function: Gets the transform component of the scene object.

Returns The transform component.

FunctionsisEnabledInHierarchy(): boolean

Function: Gets whether the scene object is enabled in the hierarchy. This property determines if the scene object and its components are visible and active.

Returns True if the scene object is enabled in the hierarchy, false otherwise.

FunctionsremoveComponent(comp: Component): boolean

Function: Removes the specified component instance from the scene object.

Parameters

comp: - The component instance to remove.

Returns True if the component was successfully removed, false otherwise.

FunctionssetEnabledInHierarchy(enabled: boolean): void

Function: Sets whether the scene object is enabled in the hierarchy.

Parameters

enabled: - True to enable the scene object in the hierarchy, false to disable it.

Examples

constructor()

let obj = new APJS.SceneObject();

Use Case

Example 1 — Object pool using clone() + setEnabledInHierarchy. Pre-spawn pool of clones from a template, acquire/release with show/hide.

@component()
export class ObjectPool extends APJS.BasicScriptComponent {
@serializeProperty
template!: APJS.SceneObject;

private pool: APJS.SceneObject[] = [];
private initialized = false;
private readonly POOL_SIZE = 10;

onUpdate(dt: number): void {
if (!this.initialized && this.template) {
this.initialized = true;
// Pre-create pool of hidden clones
for (let i = 0; i < this.POOL_SIZE; i++) {
const obj = this.template.clone();
obj.setEnabledInHierarchy(false);
this.pool.push(obj);
}
// Hide the template too
this.template.setEnabledInHierarchy(false);
}
}

acquire(x: number, y: number): APJS.SceneObject | undefined {
if (this.pool.length === 0) return undefined;
const obj = this.pool.pop()!;
obj.setEnabledInHierarchy(true);
const st = obj.getComponent("ScreenTransform") as APJS.ScreenTransform;
if (st) st.anchoredPosition = new APJS.Vector2f(x, y);
return obj;
}

release(obj: APJS.SceneObject): void {
obj.setEnabledInHierarchy(false);
this.pool.push(obj);
}
}

Example 2 — Audio manager with BGM loop + multiple SFX channels — demonstrates the BGM+SFX pattern with separate Audio Player objects

@component()
export class MultiSfxManager extends APJS.BasicScriptComponent {
@serializeProperty
bgmPlayer!: APJS.SceneObject;
@serializeProperty
clickPlayer!: APJS.SceneObject;
@serializeProperty
successPlayer!: APJS.SceneObject;
@serializeProperty
failPlayer!: APJS.SceneObject;

private bgm!: APJS.AudioComponent;
private clickSfx!: APJS.AudioComponent;
private successSfx!: APJS.AudioComponent;
private failSfx!: APJS.AudioComponent;
private initialized = false;

onUpdate(dt: number): void {
if (!this.initialized && this.bgmPlayer) {
this.bgm = this.bgmPlayer.getComponent("AudioComponent") as APJS.AudioComponent;
this.clickSfx = this.clickPlayer.getComponent("AudioComponent") as APJS.AudioComponent;
this.successSfx = this.successPlayer.getComponent("AudioComponent") as APJS.AudioComponent;
this.failSfx = this.failPlayer.getComponent("AudioComponent") as APJS.AudioComponent;
if (!this.bgm || !this.clickSfx) return;

// Start BGM (playMode set to Infinity via DSL)
this.bgm.volume = 40;
this.bgm.play();
this.initialized = true;
}
}

playClick(): void {
this.clickSfx.stop();
this.clickSfx.loopCount = 1;
this.clickSfx.volume = 100;
this.clickSfx.play();
}

playSuccess(): void {
this.successSfx.stop();
this.successSfx.loopCount = 1;
this.successSfx.volume = 100;
this.successSfx.play();
}

playFail(): void {
this.failSfx.stop();
this.failSfx.loopCount = 1;
this.failSfx.volume = 100;
this.failSfx.play();
}
}
Copyright © 2026 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalTerms of ServicePrivacy PolicyCookies