Skip to content
GameObject

[Base Class](../groups/Base Class.Base Class.md) / GameObject

GameObject Class

Base class of all entities in the scene

Logical objects such as Model, Pawn, Camera, AdvancedVehicle, BlockingVolume, etc. inherit from GameObject.

Provide functions such as copying and deleting objects, searching for and obtaining objects, sub objects, scripts, etc.

Example usage: Create a script called "GameObjectiExample" to place the model cube, cylinder, and frustum in the scene, with a parent-child tree of cube/cylinder/frustum, and mount the GameObjectiExample script to the cube. The code is as follows:

ts
@Component
export default class GameObjectExample extends Script {
    protected onStart(): void {
        let obj: GameObject = this.gameObject;
        console.log(`obj.name = ${obj.name}`);
        console.log(`obj.tag = ${obj.tag}`);
        console.log(`obj.worldTransform = ${obj.worldTransform}`);
        console.log(`obj.localTransform = ${obj.localTransform}`);
        let children = obj.getChildren();
        children.forEach(child => {
            console.log(`obj child = ${child.name}`);
        });
        let path = Cube/cylinder
        let cylinderObj = GameObject.getGameObjectByPath(path);
        console.log(`getGameObjectByPath = ${cylinderObj ? cylinderObj.name : "undefined"}`);
        path = "Cylinder/frustum"
        cylinderObj = obj.getChildByPath(path);
        console.log(`getChildByPath = ${cylinderObj ? cylinderObj.name : "undefined"}`);
        cylinderObj.onDestroyDelegate.add(()=>{
            console.log(`destroyDelegate 1 = ${cylinderObj ? cylinderObj.name : "undefined"}`);
        });
        cylinderObj.onDestroyDelegate.add(()=>{
            console.log(`destroyDelegate 2 = ${cylinderObj ? cylinderObj.name : "undefined"}`);
        });
        cylinderObj.destroy();
    }
}
@Component
export default class GameObjectExample extends Script {
    protected onStart(): void {
        let obj: GameObject = this.gameObject;
        console.log(`obj.name = ${obj.name}`);
        console.log(`obj.tag = ${obj.tag}`);
        console.log(`obj.worldTransform = ${obj.worldTransform}`);
        console.log(`obj.localTransform = ${obj.localTransform}`);
        let children = obj.getChildren();
        children.forEach(child => {
            console.log(`obj child = ${child.name}`);
        });
        let path = Cube/cylinder
        let cylinderObj = GameObject.getGameObjectByPath(path);
        console.log(`getGameObjectByPath = ${cylinderObj ? cylinderObj.name : "undefined"}`);
        path = "Cylinder/frustum"
        cylinderObj = obj.getChildByPath(path);
        console.log(`getChildByPath = ${cylinderObj ? cylinderObj.name : "undefined"}`);
        cylinderObj.onDestroyDelegate.add(()=>{
            console.log(`destroyDelegate 1 = ${cylinderObj ? cylinderObj.name : "undefined"}`);
        });
        cylinderObj.onDestroyDelegate.add(()=>{
            console.log(`destroyDelegate 2 = ${cylinderObj ? cylinderObj.name : "undefined"}`);
        });
        cylinderObj.destroy();
    }
}

Hierarchy

Table of contents

Properties

onBeforeDestroyDelegate: MulticastDelegate<() => void> other
Event callback before object destruction
onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Monitor custom attribute synchronization events
onDestroyDelegate: MulticastDelegate<() => void> other
Event callback after object destruction
onPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>
Monitor system replicated events

Accessors

actorFlagValue(): number other
Get object tags
actorLevel(): number other
Obtain Actor Level
assetId(): string other
Retrieve the UID of the resource currently being used by the object
gameObjectId(): string other
Get the unique identification of an object (a string that uniquely identifies an object).
isDestroyed(): boolean other
Has the current object been destroyed
isReady(): boolean other
Current object status
localTransform(): Transform other
Local transformation of the current object
name(): string other
Return the current object name
netStatus(): NetStatus other
Get the current object synchronization status
parent(): GameObject other
Retrieve the current parent object
tag(): string other
Get the tag of the current object
worldTransform(): Transform other
Current object world transformation

Methods

addComponent<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>, bInReplicates?: boolean): T: extends Script<T> other
Add a script component
asyncGetChildByName(name: string): Promise<GameObject> other
Asynchronous search for sub objects based on their names
asyncReady(): Promise<GameObject> other
Return after the object is ready
clone(gameObjectInfo?: GameObjectInfo): GameObject other
Copy Objects
destroy(): void other
delete object
getBoundingBox(nonColliding?: boolean, includeFromChild?: boolean, outer?: Vector): Vector other
Get the size of the object's bounding box
getBounds(onlyCollidingComponents: boolean, originOuter: Vector, boxExtentOuter: Vector, includeFromChild?: boolean): void other
Obtain object boundaries
getChildByGameObjectId(gameObjectId: string): GameObject other
Search for sub objects based on gameObjectid
getChildByName(name: string): GameObject other
Search for sub objects by name
getChildByPath(path: string): GameObject other
Find sub objects according to path
getChildren(): GameObject[] other
Obtain sub objects
getChildrenBoundingBoxCenter(outer?: Vector): Vector other
Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0])
getChildrenByName(name: string): GameObject[] other
Search for all sub objects by name
getComponent<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T> other
Get the component of the specified type
getComponentPropertys<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>): Map<string, IPropertyOptions> other
Get property of script component
getComponents<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T>[] other
Get all component of the specified type
getCustomProperties(): string[] other
Get all customize property
getCustomProperty<T: extends CustomPropertyType>(propertyName: string): T: extends CustomPropertyType other
Get customize property
getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getVisibility(): boolean other
Obtain whether the object is displayed
isPrefabActor(): boolean other
Return whether the current object is a prefabricated body
moveBy(velocity: Vector, isLocal?: boolean): void other
Smoothly move an object over time according to a given velocity vector
moveTo(targetPosition: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly move from the current position to the target position within the specified time
rotateBy(rotation: Quaternion Rotation, multiplier: number, isLocal?: boolean): void other
Rotate the object smoothly over time according to the given rotation amount
rotateTo(targetRotation: Quaternion Rotation, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current rotation to the target rotation within the specified time
scaleBy(scale: Vector, isLocal?: boolean): void other
Smoothly scale objects over time using a given scaling vector per second
scaleTo(targetScale: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current scale to the target scale within the specified time
setAbsolute(absolutePosition?: boolean, absoluteRotation?: boolean, absoluteScale?: boolean): void other
Set whether the object localTransform is relative to the parent object or the world
setCustomProperty(propertyName: string, value: undefined CustomPropertyType): void other
Set custom attributes
setVisibility(status: boolean PropertyStatus, propagateToChildren?: boolean): void other
Set whether the object is displayed
stopMove(): void other
Interrupt further movement of moveTo() and moveBy()
stopRotate(): void other
Interrupt further rotation from rotateTo() or rotateBy()
stopScale(): void other
Interrupt further scale from ScaleTo() or ScaleBy()
asyncFindGameObjectById(gameObjectId: string): Promise<GameObject> other
Asynchronous search for GameObject through gameObjectid
asyncGetGameObjectByPath(path: string): Promise<GameObject> other
Asynchronously find objects through path
asyncSpawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): Promise<T: extends GameObject<T>> other
Asynchronous construction of an object
bulkPivotTo(gameObjects: GameObject[], transforms: Transform[]): void other
Batch set position
findGameObjectById(gameObjectId: string): GameObject other
Search for objects through gameObjectid
findGameObjectByName(name: string): GameObject other
Search for objects by name
findGameObjectsByName(name: string): GameObject[] other
Search for objects by name
findGameObjectsByTag(tag: string): GameObject[] other
Get objects through customize tag
getGameObjectByPath(path: string): GameObject other
Search for objects through paths
spawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): T: extends GameObject<T> other
Construct an object

Properties

onBeforeDestroyDelegate

onBeforeDestroyDelegate: MulticastDelegate<() => void> other

Event callback before object destruction


onCustomPropertyChange

onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other

Monitor custom attribute synchronization events

ts
this.onCustomPropertyChange.add((path, value, oldValue) => {
    Console. log (the ` property ${path} change, the new value is ${value}, the old value is ${oldValue} `);
});
this.onCustomPropertyChange.add((path, value, oldValue) => {
    Console. log (the ` property ${path} change, the new value is ${value}, the old value is ${oldValue} `);
});

onDestroyDelegate

onDestroyDelegate: MulticastDelegate<() => void> other

Event callback after object destruction


onPropertyChange

onPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>

Monitor system replicated events

ts
this.onPropertyChange.add((path, value, oldValue) => {
    Console. log (the ` property ${path} change, the new value is ${value}, the old value is ${oldValue} `);
});
this.onPropertyChange.add((path, value, oldValue) => {
    Console. log (the ` property ${path} change, the new value is ${value}, the old value is ${oldValue} `);
});

Accessors

actorFlagValue

get actorFlagValue(): number other

set actorFlagValue(v): void other

Get object tags

Returns

number

Set object tags

Parameters

vnumber

actorLevel

get actorLevel(): number other

Obtain Actor Level

Returns

number

assetId

get assetId(): string other

Retrieve the UID of the resource currently being used by the object

Returns

string

gameObjectId

get gameObjectId(): string other

Get the unique identification of an object (a string that uniquely identifies an object).

Returns

string

isDestroyed

get isDestroyed(): boolean other

Has the current object been destroyed

Returns

boolean

isReady

get isReady(): boolean other

Current object status

Returns

boolean

localTransform

get localTransform(): Transform other

set localTransform(transform): void other

Local transformation of the current object

Returns

Transform

Local transformation of the current object

Parameters

transformTransform

name

get name(): string other

set name(name): void other

Editor

Return the current object name

Returns

stringname

Editor

Set object name

Parameters

name stringUsage: Name that needs to be set

netStatus

get netStatus(): NetStatus other

Get the current object synchronization status

Returns

NetStatusmw.NetStatus

parent

get parent(): GameObject other

set parent(newParent): void other

Retrieve the current parent object

Returns

GameObjectFather object

Set parent object

Parameters

newParentGameObject

tag

get tag(): string other

set tag(tag): void other

Get the tag of the current object

Returns

stringTag

Set the label for the current object

Parameters

tag stringTag

worldTransform

get worldTransform(): Transform other

set worldTransform(transform): void other

Current object world transformation

Returns

Transform

Current object world transformation

Parameters

transformTransform

Methods

addComponent

addComponent<T>(constructor, bInReplicates?): T other

Add a script component

Parameters

constructor (...args: unknown[]) => TScriptComponentClass Add the type of script
default: null
bInReplicates? booleanEnable sync
default: call on the server, and sync will be enabled by default; When call on the client, default is not sync.

Returns

TT Newly added script component

Type parameters

Textends Script<T>

asyncGetChildByName

asyncGetChildByName(name): Promise<GameObject> other

Editor

Asynchronous search for sub objects based on their names

Parameters

name stringUsage: Name
Range: The maximum length of the string is determined by the length of the name of different objects.

Returns

Promise<GameObject>Object searched for

asyncReady

asyncReady(): Promise<GameObject> other

Return after the object is ready

Returns

Promise<GameObject>Prepared object

clone

clone(gameObjectInfo?): GameObject other

Editor

Copy Objects

Parameters

gameObjectInfo? GameObjectInfoUsage: Clone object information
default: null

Returns

GameObjectCloned object

destroy

destroy(): void other

delete object


getBoundingBox

getBoundingBox(nonColliding?, includeFromChild?, outer?): Vector other

Get the size of the object's bounding box

Parameters

nonColliding? booleanUsage: means to include non collision component in the bounding box
default: false
includeFromChild? booleanUsage: If true, recursive sub object
default: false
outer? VectorUsage: Vector object for receiving converted data
default: null

Returns

Vectormw.Vector

Precautions

If outer is not empty, return outer; otherwise, return a new Vector object. It is recommended to pass in outer to reduce the number of new objects


getBounds

getBounds(onlyCollidingComponents, originOuter, boxExtentOuter, includeFromChild?): void other

Obtain object boundaries

Parameters

onlyCollidingComponents booleanUsage: whether only collision component are included.
originOuter VectorUsage: Output parameter, set to the center point coordinates of the object.
boxExtentOuter VectorUsage: Output parameter, set to half the size of the object.
includeFromChild? booleanUsage: whether to recursively include sub objects
default: undefined

getChildByGameObjectId

getChildByGameObjectId(gameObjectId): GameObject other

Search for sub objects based on gameObjectid

Parameters

gameObjectId stringgameObjectId
range: The maximum length of a string is determine by the length of IDs of different types.

Returns

GameObjectObject searched for

getChildByName

getChildByName(name): GameObject other

Editor

Search for sub objects by name

Parameters

name stringUsage: Name
Range: The maximum length of the string is determined by the length of the name of different objects.

Returns

GameObjectObject searched for

getChildByPath

getChildByPath(path): GameObject other

Find sub objects according to path

Parameters

path stringUsage: path
range: The maximum length of the string is determine according to different path lengths.

Returns

GameObjectObject searched for

getChildren

getChildren(): GameObject[] other

Obtain sub objects

Returns

GameObject[]Array<GameObject>

getChildrenBoundingBoxCenter

getChildrenBoundingBoxCenter(outer?): Vector other

Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0])

Parameters

outer? VectorUsage: Vector object for receiving converted data
default: null

Returns

Vectormw.Vector

Precautions

If outer is not empty, return outer; otherwise, return a new Vector object. It is recommended to pass in outer to reduce the number of new objects


getChildrenByName

getChildrenByName(name): GameObject[] other

Search for all sub objects by name

Parameters

name stringUsage: sub object name
range: the maximum length of the string is determine according to the length of different types of names and IDs.

Returns

GameObject[]Matching sub object array

getComponent

getComponent<T>(constructor?): T other

Get the component of the specified type

Parameters

constructor? (...args: unknown[]) => TScript type
default: null

Returns

TScript component

Usage example: Create a script named "NewScript1" and obtain the NewScript script through getComponent. The code is as follows:

ts
import NewScript from "./NewScript";
@Component
export default class NewScript1 extends Script {
    protected onStart(): void {
        const script = this.gameObject.getComponent(NewScript);
    }
}
import NewScript from "./NewScript";
@Component
export default class NewScript1 extends Script {
    protected onStart(): void {
        const script = this.gameObject.getComponent(NewScript);
    }
}

Type parameters

Textends Script<T>

getComponentPropertys

getComponentPropertys<T>(constructor): Map<string, IPropertyOptions> other

Get property of script component

Parameters

constructor (...args: unknown[]) => TScript type
default: null

Returns

Map<string, IPropertyOptions>All property of the component Map<key: IPropertyOptions>

Type parameters

Textends Script<T>

getComponents

getComponents<T>(constructor?): T[] other

Get all component of the specified type

Parameters

constructor? (...args: unknown[]) => TScript type
default: null

Returns

T[]List of script component

Type parameters

Textends Script<T>

getCustomProperties

getCustomProperties(): string[] other

Get all customize property

Returns

string[]Attribute Name List
ts
const attributes = this.getAttributes();
console.log(attributes);
// ["name", "age"]
const attributes = this.getAttributes();
console.log(attributes);
// ["name", "age"]

getCustomProperty

getCustomProperty<T>(propertyName): T other

Get customize property

Parameters

propertyNamestring

Returns

TProperty value

Type parameters

Textends CustomPropertyType

getCustomPropertyChangeDelegate

getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other

Event proxy triggered when a given object property is modified

Parameters

property stringName of object property

Returns

Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>Proxy Object

getPropertyChangeDelegate

getPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other

Event proxy triggered when a given object property is modified

Parameters

property stringName of object property, for example: 'x' 'rotation. x'

Returns

Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>Proxy Object

getVisibility

getVisibility(): boolean other

Obtain whether the object is displayed

Returns

booleanbool

isPrefabActor

isPrefabActor(): boolean other

Editor

Return whether the current object is a prefabricated body

Returns

booleanname

moveBy

moveBy(velocity, isLocal?): void other

Smoothly move an object over time according to a given velocity vector

Parameters

velocity VectorUsage: Speed
isLocal? booleanUsage: Is the local space effective? Default: true

Usage example: Calling method

ts
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.moveBy(new Vector(10, 10, 0), true);
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.moveBy(new Vector(10, 10, 0), true);

moveTo

moveTo(targetPosition, time, isLocal?, onComplete?): void other

Smoothly move from the current position to the target position within the specified time

Parameters

targetPosition VectorUsage: target position
time numberUsage: Slow down time range:>0 type: number
isLocal? booleanUsage: Is the local space effective? Default: true
onComplete? () => voidUsage: Complete callback method default: undefined

Usage example: Calling method

ts
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.moveTo(new Vector(1000, 0, 0), 10, true, () => {
   console.log("moveTo complete");
});
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.moveTo(new Vector(1000, 0, 0), 10, true, () => {
   console.log("moveTo complete");
});

rotateBy

rotateBy(rotation, multiplier, isLocal?): void other

Rotate the object smoothly over time according to the given rotation amount

Parameters

rotation Quaternion RotationUsage: Rotation speed
multiplier numberUsage: Rotation multiplier range:>0 type: number
isLocal? booleanUsage: Is the local space effective? Default: true

Usage example: Calling method

ts
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.rotateBy(new Rotation(1, 0, 1), 5, true);
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.rotateBy(new Rotation(1, 0, 1), 5, true);

rotateTo

rotateTo(targetRotation, time, isLocal?, onComplete?): void other

Smoothly changes from the current rotation to the target rotation within the specified time

Parameters

targetRotation Quaternion RotationUsage: target orientation
time numberUsage: Slow down time range:>0 type: number
isLocal? booleanUsage: Is the local space effective? Default: true
onComplete? () => voidUsage: Complete callback method default: undefined

Usage example: Calling method

ts
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.rotateTo(new Rotation(45, 0, 0), 10, true, () => {
   console.log("rotateTo complete");
});
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.rotateTo(new Rotation(45, 0, 0), 10, true, () => {
   console.log("rotateTo complete");
});

scaleBy

scaleBy(scale, isLocal?): void other

Smoothly scale objects over time using a given scaling vector per second

Parameters

scale VectorUsage: scale speed
isLocal? booleanUsage: Is the local space effective? Default: true

Usage example: Calling method

ts
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.scaleBy(new Vector(1, 1, 0), true);
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.scaleBy(new Vector(1, 1, 0), true);

scaleTo

scaleTo(targetScale, time, isLocal?, onComplete?): void other

Smoothly changes from the current scale to the target scale within the specified time

Parameters

targetScale VectorUsage: target scale
time numberUsage: Slow down time range:>0 type: number
isLocal? booleanUsage: Is the local space effective? Default: true
onComplete? () => voidUsage: Complete callback method default: undefined

Usage example: Calling method

ts
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.scaleTo(new Vector(2, 2, 0), 10, true, () => {
   console.log("scaleTo complete");
});
let cube = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
cube.scaleTo(new Vector(2, 2, 0), 10, true, () => {
   console.log("scaleTo complete");
});

setAbsolute

setAbsolute(absolutePosition?, absoluteRotation?, absoluteScale?): void other

Editor

Set whether the object localTransform is relative to the parent object or the world

Parameters

absolutePosition? booleanWhether the position is relative to the world default: false
absoluteRotation? booleanWhether the rotation is relative to the world default: false
absoluteScale? booleanWhether scale is relative to the world default: false

setCustomProperty

setCustomProperty(propertyName, value): void other

Set custom attributes

Parameters

propertyName string-
value undefined CustomPropertyTypeProperty value

setVisibility

setVisibility(status, propagateToChildren?): void other

Set whether the object is displayed

Parameters

status boolean PropertyStatusUsage: Status
propagateToChildren? booleanDo you want to set sub objects?
default: false

stopMove

stopMove(): void other

Interrupt further movement of moveTo() and moveBy()


stopRotate

stopRotate(): void other

Interrupt further rotation from rotateTo() or rotateBy()


stopScale

stopScale(): void other

Interrupt further scale from ScaleTo() or ScaleBy()


asyncFindGameObjectById

Static asyncFindGameObjectById(gameObjectId): Promise<GameObject> other

Asynchronous search for GameObject through gameObjectid

Parameters

gameObjectId stringUsage: The gameObjectId of an object
range: The maximum length of a string is determine according to the length of asset IDs of different types.

Returns

Promise<GameObject>The object corresponding to gameObjectid

The default is 10 seconds, which can be set through ScriptingSettings.setGlobalAsyncOverTime (1000 * 10).


asyncGetGameObjectByPath

Static asyncGetGameObjectByPath(path): Promise<GameObject> other

Asynchronously find objects through path

Parameters

path stringUsage: object path
range: the maximum length of the string is determine according to the length of the path ID. No restrictions.

Returns

Promise<GameObject>Objects corresponding to path

asyncSpawn

Static asyncSpawn<T>(assetId, gameObjectInfo?): Promise<T> other

Asynchronous construction of an object

Parameters

assetId stringAsset ID
range: The maximum length of a string is determine according to the length of asset IDs of different types.
gameObjectInfo? GameObjectInfoInformation about building objects
default: optional

Returns

Promise<T>Constructed object

If the resource does not exist, we will download it first and then create it

Usage example: Call method

ts
let obj = await GameObject.asyncSpawn<Model>("197386", {
    replicates: true,
    transform: new Transform()
});
let obj = await GameObject.asyncSpawn<Model>("197386", {
    replicates: true,
    transform: new Transform()
});

Type parameters

Textends GameObject<T>

bulkPivotTo

Static bulkPivotTo(gameObjects, transforms): void other

Batch set position

Parameters

gameObjects GameObject[]Usage: Preparing to update the list of GameObjects for Transform
transforms Transform[]Usage: Transform list of target values provided by position

findGameObjectById

Static findGameObjectById(gameObjectId): GameObject other

Search for objects through gameObjectid

Parameters

gameObjectId stringUsage: The gameObjectId of an object
range: The maximum length of a string is determine according to the length of asset IDs of different types.

Returns

GameObjectThe object corresponding to gameObjectid

findGameObjectByName

Static findGameObjectByName(name): GameObject other

Search for objects by name

Parameters

name stringUsage: Object name
range: The maximum length of a string is determined by the ID length of different types of names.

Returns

GameObjectReturn the first found object. If there are multiple objects with the same name, randomly return one

Precautions

The global query API will consume some query time, which may reduce the performance of the game.


findGameObjectsByName

Static findGameObjectsByName(name): GameObject[] other

Search for objects by name

Parameters

name stringUsage: object name
range: the maximum length of the string is determine according to the length of the ID of different types of asset.

Returns

GameObject[]Return all found objects

Precautions

The global query API will consume some query time, which may reduce the performance of the game.


findGameObjectsByTag

Static findGameObjectsByTag(tag): GameObject[] other

Get objects through customize tag

Parameters

tag stringUsage: customize tag
range: the maximum length of the string does not exceed 200 characters

Returns

GameObject[]Array<GameObject>

getGameObjectByPath

Static getGameObjectByPath(path): GameObject other

Search for objects through paths

Parameters

path stringUsage: object path
range: the maximum length of the string is determine according to the length of the path ID. No restrictions.

Returns

GameObjectReturn the first object found. If there are multiple objects with the same name, return the first one found

spawn

Static spawn<T>(assetId, gameObjectInfo?): T other

Construct an object

Parameters

assetId stringAsset ID
range: depends on the length of asset ID
gameObjectInfo? GameObjectInfoBuild object information
default: optional
range: The maximum length of the string is determined by the length of different types of resource IDs.

Returns

TConstructed object

Usage example: Calling method

ts
let obj = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});
let obj = GameObject.spawn<Model>("197386", {
   replicates: true,
   transform: new Transform()
});

Type parameters

Textends GameObject<T>