[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:
@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
Base
↳
GameObject
↳↳
Model
↳↳
Pawn
↳↳
Camera
↳↳
Effect
↳↳
IKAnchor
↳↳
Sound
↳↳
Trigger
↳↳
UIWidget
↳↳
WaterVolume
↳↳
HotWeapon
↳↳
Interactor
↳↳
PointLight
↳↳
ForceVolume
↳↳
Impulse
↳↳
UIObject
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
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
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 object tags Returns
| Set object tags Parameters
|
actorLevel
• | ||
---|---|---|
Obtain Actor Level Returns
|
assetId
• | ||
---|---|---|
Retrieve the UID of the resource currently being used by the object Returns
|
gameObjectId
• | ||
---|---|---|
Get the unique identification of an object (a string that uniquely identifies an object). Returns
|
isDestroyed
• | ||
---|---|---|
Has the current object been destroyed Returns
|
isReady
• | ||
---|---|---|
Current object status Returns
|
localTransform
• | • | ||||
---|---|---|---|---|---|
Local transformation of the current object Returns
| Local transformation of the current object Parameters
|
name
• | • | ||||
---|---|---|---|---|---|
Return the current object name Returns
|
Set object name Parameters
|
netStatus
• | ||
---|---|---|
Get the current object synchronization status Returns
|
parent
• | • | ||||
---|---|---|---|---|---|
Retrieve the current parent object Returns
| Set parent object Parameters
|
tag
• | • | ||||
---|---|---|---|---|---|
Get the tag of the current object Returns
| Set the label for the current object Parameters
|
worldTransform
• | • | ||||
---|---|---|---|---|---|
Current object world transformation Returns
| Current object world transformation Parameters
|
Methods
addComponent
• addComponent<T
>(constructor
, bInReplicates?
): T
other
Add a script component
Parameters
constructor (...args : unknown []) => T | ScriptComponentClass Add the type of script default: null |
---|---|
bInReplicates? boolean | Enable sync default: call on the server, and sync will be enabled by default; When call on the client, default is not sync. |
Returns
T | T Newly added script component |
---|
Type parameters
T | extends Script <T > |
---|
asyncGetChildByName
• asyncGetChildByName(name
): Promise
<GameObject
> other
Editor
Asynchronous search for sub objects based on their names
Parameters
name string | Usage: 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? GameObjectInfo | Usage: Clone object information default: null |
---|
Returns
GameObject | Cloned 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? boolean | Usage: means to include non collision component in the bounding box default: false |
---|---|
includeFromChild? boolean | Usage: If true, recursive sub object default: false |
outer? Vector | Usage: Vector object for receiving converted data default: null |
Returns
Vector | mw.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 boolean | Usage: whether only collision component are included. |
---|---|
originOuter Vector | Usage: Output parameter, set to the center point coordinates of the object. |
boxExtentOuter Vector | Usage: Output parameter, set to half the size of the object. |
includeFromChild? boolean | Usage: whether to recursively include sub objects default: undefined |
getChildByGameObjectId
• getChildByGameObjectId(gameObjectId
): GameObject
other
Search for sub objects based on gameObjectid
Parameters
gameObjectId string | gameObjectId range: The maximum length of a string is determine by the length of IDs of different types. |
---|
Returns
GameObject | Object searched for |
---|
getChildByName
• getChildByName(name
): GameObject
other
Editor
Search for sub objects by name
Parameters
name string | Usage: Name Range: The maximum length of the string is determined by the length of the name of different objects. |
---|
Returns
GameObject | Object searched for |
---|
getChildByPath
• getChildByPath(path
): GameObject
other
Find sub objects according to path
Parameters
path string | Usage: path range: The maximum length of the string is determine according to different path lengths. |
---|
Returns
GameObject | Object 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? Vector | Usage: Vector object for receiving converted data default: null |
---|
Returns
Vector | mw.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 string | Usage: 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 []) => T | Script type default: null |
---|
Returns
T | Script component |
---|
Usage example: Create a script named "NewScript1" and obtain the NewScript script through getComponent. The code is as follows:
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
T | extends Script <T > |
---|
getComponentPropertys
• getComponentPropertys<T
>(constructor
): Map
<string
, IPropertyOptions
> other
Get property of script component
Parameters
constructor (...args : unknown []) => T | Script type default: null |
---|
Returns
Map <string , IPropertyOptions > | All property of the component Map<key: IPropertyOptions> |
---|
Type parameters
T | extends Script <T > |
---|
getComponents
• getComponents<T
>(constructor?
): T
[] other
Get all component of the specified type
Parameters
constructor? (...args : unknown []) => T | Script type default: null |
---|
Returns
T [] | List of script component |
---|
Type parameters
T | extends Script <T > |
---|
getCustomProperties
• getCustomProperties(): string
[] other
Get all customize property
Returns
string [] | Attribute Name List |
---|
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
propertyName | string |
---|
Returns
T | Property value |
---|
Type parameters
T | extends 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 string | Name 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 string | Name 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
boolean | bool |
---|
isPrefabActor
• isPrefabActor(): boolean
other
Editor
Return whether the current object is a prefabricated body
Returns
boolean | name |
---|
moveBy
• moveBy(velocity
, isLocal?
): void
other
Smoothly move an object over time according to a given velocity vector
Parameters
velocity Vector | Usage: Speed |
---|---|
isLocal? boolean | Usage: Is the local space effective? Default: true |
Usage example: Calling method
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 Vector | Usage: target position |
---|---|
time number | Usage: Slow down time range:>0 type: number |
isLocal? boolean | Usage: Is the local space effective? Default: true |
onComplete? () => void | Usage: Complete callback method default: undefined |
Usage example: Calling method
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 Rotation | Usage: Rotation speed |
---|---|
multiplier number | Usage: Rotation multiplier range:>0 type: number |
isLocal? boolean | Usage: Is the local space effective? Default: true |
Usage example: Calling method
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 Rotation | Usage: target orientation |
---|---|
time number | Usage: Slow down time range:>0 type: number |
isLocal? boolean | Usage: Is the local space effective? Default: true |
onComplete? () => void | Usage: Complete callback method default: undefined |
Usage example: Calling method
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 Vector | Usage: scale speed |
---|---|
isLocal? boolean | Usage: Is the local space effective? Default: true |
Usage example: Calling method
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 Vector | Usage: target scale |
---|---|
time number | Usage: Slow down time range:>0 type: number |
isLocal? boolean | Usage: Is the local space effective? Default: true |
onComplete? () => void | Usage: Complete callback method default: undefined |
Usage example: Calling method
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? boolean | Whether the position is relative to the world default: false |
---|---|
absoluteRotation? boolean | Whether the rotation is relative to the world default: false |
absoluteScale? boolean | Whether scale is relative to the world default: false |
setCustomProperty
• setCustomProperty(propertyName
, value
): void
other
Set custom attributes
Parameters
propertyName string | - |
---|---|
value undefined CustomPropertyType | Property value |
setVisibility
• setVisibility(status
, propagateToChildren?
): void
other
Set whether the object is displayed
Parameters
status boolean PropertyStatus | Usage: Status |
---|---|
propagateToChildren? boolean | Do 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 string | Usage: 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 string | Usage: 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 string | Asset ID range: The maximum length of a string is determine according to the length of asset IDs of different types. |
---|---|
gameObjectInfo? GameObjectInfo | Information 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
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
T | extends 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 string | Usage: 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
GameObject | The object corresponding to gameObjectid |
---|
findGameObjectByName
• Static
findGameObjectByName(name
): GameObject
other
Search for objects by name
Parameters
name string | Usage: Object name range: The maximum length of a string is determined by the ID length of different types of names. |
---|
Returns
GameObject | Return 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 string | Usage: 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 string | Usage: 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 string | Usage: object path range: the maximum length of the string is determine according to the length of the path ID. No restrictions. |
---|
Returns
GameObject | Return 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 string | Asset ID range: depends on the length of asset ID |
---|---|
gameObjectInfo? GameObjectInfo | Build object information default: optional range: The maximum length of the string is determined by the length of different types of resource IDs. |
Returns
T | Constructed object |
---|
Usage example: Calling method
let obj = GameObject.spawn<Model>("197386", {
replicates: true,
transform: new Transform()
});
let obj = GameObject.spawn<Model>("197386", {
replicates: true,
transform: new Transform()
});
Type parameters
T | extends GameObject <T > |
---|