Skip to content
Pawn

[Character System](../groups/Character System.Character System.md) / Pawn

Pawn Class

As the base class of Player character and non object Player character, Pawn is a game object that can be control through Player controller or logical script.

Hierarchy

Table of contents

Properties

click

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

customTimeDilation(): number other
Expansion time velocity
player(): Player other
Player Object
click

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

setOutline(enabled: boolean, color?: LinearColor, width?: number): void other
Add outline Effect
setPostProcessOutline(enabled: boolean, color?: LinearColor, width?: number): void other
Add post-processing strokes
click

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

Accessors


customTimeDilation

get customTimeDilation(): number other

set customTimeDilation(value): void other

Expansion time velocity

Precautions

The inflation time velocity of the Pawn object. The modified self time velocity is the value multiplied by the world time velocity. The default value is 1. The standalone mode can set the inflation to 0 to achieve a time pause effect, while the online mode has a minimum setting of 0.1

Usage example: create a script named "Example_Pawn_CustomTimeDifference", place it in the object bar, open the script, enter the following code to save, run the game, and you will see the jump delay effect after modifying the Player's time expansion speed in the scene to 0.5 times the original. The code is as follows:

ts
@Component
export default class Example_Pawn_CustomTimeDilation extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The character animation will not be affected after the current modification time expands, and you can turn off the related optimization of character
         Player.asyncGetLocalPlayer().then((player) => {
             console.warn("client close setOptimization")
             mw.AvatarSettings.setOptimization(player.character, false, false);
         })
         // The following code is only executed on the client side
         if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Add a key method: press the keyboard "1" to modify the time expansion speed of Player to 0.5 times of the original, and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myPlayer.character.customTimeDilation = 0.5;
                console.log("My pawn customTimeDilation: " + myPlayer.character.customTimeDilation);
                // Make the player character jump
                (myPlayer.character as Character).jump();
            });
        }
    }
}
@Component
export default class Example_Pawn_CustomTimeDilation extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The character animation will not be affected after the current modification time expands, and you can turn off the related optimization of character
         Player.asyncGetLocalPlayer().then((player) => {
             console.warn("client close setOptimization")
             mw.AvatarSettings.setOptimization(player.character, false, false);
         })
         // The following code is only executed on the client side
         if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Add a key method: press the keyboard "1" to modify the time expansion speed of Player to 0.5 times of the original, and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myPlayer.character.customTimeDilation = 0.5;
                console.log("My pawn customTimeDilation: " + myPlayer.character.customTimeDilation);
                // Make the player character jump
                (myPlayer.character as Character).jump();
            });
        }
    }
}

Returns

number

Expansion time velocity

Precautions

The inflation time velocity of the Pawn object. The modified self time velocity is the value multiplied by the world time velocity. The default value is 1. The standalone mode can set the inflation to 0 to achieve a time pause effect, while the online mode has a minimum setting of 0.1

Example usage: Create a script called "Instance-Pawn_Customs Time Dilation", place it in the object bar, open the script, enter the following code to save, run the game, and you will modify the player's time dilation speed in the scene to 0.5 times the original, and then see the delayed jumping effect. The code is as follows:

ts
@Component
export default class Example_Pawn_CustomTimeDilation extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The character animation will not be affected after the current modification time expands, and you can turn off the related optimization of character
         Player.asyncGetLocalPlayer().then((player) => {
             console.warn("client close setOptimization")
             mw.AvatarSettings.setOptimization(player.character, false, false);
         })
         // The following code is only executed on the client side
         if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Add a key method: press the keyboard "1" to modify the time expansion speed of Player to 0.5 times of the original, and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myPlayer.character.customTimeDilation = 0.5;
                console.log("My pawn customTimeDilation: " + myPlayer.character.customTimeDilation);
                // Make the player character jump
                (myPlayer.character as Character).jump();
            });
        }
    }
}
@Component
export default class Example_Pawn_CustomTimeDilation extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The character animation will not be affected after the current modification time expands, and you can turn off the related optimization of character
         Player.asyncGetLocalPlayer().then((player) => {
             console.warn("client close setOptimization")
             mw.AvatarSettings.setOptimization(player.character, false, false);
         })
         // The following code is only executed on the client side
         if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Add a key method: press the keyboard "1" to modify the time expansion speed of Player to 0.5 times of the original, and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myPlayer.character.customTimeDilation = 0.5;
                console.log("My pawn customTimeDilation: " + myPlayer.character.customTimeDilation);
                // Make the player character jump
                (myPlayer.character as Character).jump();
            });
        }
    }
}

Parameters

valuenumber

player

get player(): Player other

Player Object

Precautions

The Player who controls the current Pawn object, read-only.

Usage example: create a script named "Example_Pawn_Player", place it in the object bar, open the script, enter the following code to save, run the game, obtain the Player through the player, and you will see the printed userId and instanceId in the console. The code is as follows:

ts
@Component
export default class Example_Pawn_Player extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The following code is only executed on the client side
         if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Print the player's (own) userId and instanceId and compare them
            console.log("My userId: " + myPlayer.userId);
            // Get the Player (himself) through owner, print userId and instanceId and compare them
            let myCharacter = myPlayer.character;
            let mmyPlayer_2 = myCharacter.player;
            console.log("My userId: " + mmyPlayer_2.userId);
        }
    }
}
@Component
export default class Example_Pawn_Player extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
         // The following code is only executed on the client side
         if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Print the player's (own) userId and instanceId and compare them
            console.log("My userId: " + myPlayer.userId);
            // Get the Player (himself) through owner, print userId and instanceId and compare them
            let myCharacter = myPlayer.character;
            let mmyPlayer_2 = myCharacter.player;
            console.log("My userId: " + mmyPlayer_2.userId);
        }
    }
}

Returns

Player

Methods


setOutline

setOutline(enabled, color?, width?): void other

Add outline Effect

Parameters

enabled booleanUsage: Do you want to enable tracing
color? LinearColorUsage: stroke color default: LinearColor.black
width? numberUsage: outline width default: 2 range: [0, 10] type: floating point

Precautions

Add a stroke effect to the Pawn object, which will be obscured by other objects.

Usage example: Drag the resource "197386" into the priority loading bar. Create a script named 'Instance-Pawn_Outline', place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard '1' to add or remove regular strokes for player Pawn (which will be obscured), press the keyboard '2' to add or remove post-processing strokes for player Pawn (which will not be obscured). The code is as follows:

ts
@Component
export default class Example_Pawn_Outline extends Script {
    // Declare variables
    flag: boolean;
    flag_advance: boolean;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // Set the current stroke status
        this.flag = false;
        this.flag_advance = false;
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Create a cube
            let cube = GameObject.spawn("197386",{ transform: new Transform(new Vector(200, 0, 0), Rotation.zero, new Vector(1, 1, 2))}) as Model;
            cube.setCollision(CollisionStatus.Off);
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Add a key method: press "1" on the keyboard to add or remove ordinary outline to Player Pawn (it will be blocked)
            InputUtil.onKeyDown(Keys.One, () => {
                if(this.flag) {
                    myPlayer.character.setOutline(false);
                } else {
                    myPlayer.character.setOutline(true, LinearColor.red, 1);
                }
                this.flag = !this.flag;
            });
            // Add a button method: Press keyboard "2" to add or remove post-processing strokes for player Pawn (not obscured)
            InputUtil.onKeyDown(Keys.Two, () => {
                if(this.flag_advance) {
                    myPlayer.character.setPostProcessOutline(false);
                } else {
                    myPlayer.character.setPostProcessOutline(true, LinearColor.red, 1);
                }
                this.flag_advance = !this.flag_advance;
            });
        }
    }
}
@Component
export default class Example_Pawn_Outline extends Script {
    // Declare variables
    flag: boolean;
    flag_advance: boolean;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // Set the current stroke status
        this.flag = false;
        this.flag_advance = false;
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Create a cube
            let cube = GameObject.spawn("197386",{ transform: new Transform(new Vector(200, 0, 0), Rotation.zero, new Vector(1, 1, 2))}) as Model;
            cube.setCollision(CollisionStatus.Off);
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Add a key method: press "1" on the keyboard to add or remove ordinary outline to Player Pawn (it will be blocked)
            InputUtil.onKeyDown(Keys.One, () => {
                if(this.flag) {
                    myPlayer.character.setOutline(false);
                } else {
                    myPlayer.character.setOutline(true, LinearColor.red, 1);
                }
                this.flag = !this.flag;
            });
            // Add a button method: Press keyboard "2" to add or remove post-processing strokes for player Pawn (not obscured)
            InputUtil.onKeyDown(Keys.Two, () => {
                if(this.flag_advance) {
                    myPlayer.character.setPostProcessOutline(false);
                } else {
                    myPlayer.character.setPostProcessOutline(true, LinearColor.red, 1);
                }
                this.flag_advance = !this.flag_advance;
            });
        }
    }
}

setPostProcessOutline

setPostProcessOutline(enabled, color?, width?): void other

Add post-processing strokes

Parameters

enabled booleanUsage: Do you want to enable tracing
color? LinearColorUsage: stroke color default: LinearColor.red
width? numberUsage: outline width default: 1 range: [0, 10] type: floating point

Precautions

Add an advanced outline effect to the Pawn object, and the outline effect will not be blocked by other objects.

Usage example: drag the used asset: "197386" into the priority loading column. Create a script called 'Instance-Pawn_PostProcessOutline', place it in the object bar, open the script, enter the following code to save, run the game, and you will create a cube in the scene. Pressing the keyboard '2' can add or remove red stroke effects that are not obscured by cubes for local players. The code is as follows:

ts
@Component
export default class Example_Pawn_PostProcessOutline extends Script {
    // Declare variables
    flag: boolean;
    flag_advance: boolean;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // Set the current stroke status
        this.flag = false;
        this.flag_advance = false;
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Create a cube
            let cube = GameObject.spawn("197386",{ transform: new Transform(new Vector(200, 0, 0), Rotation.zero, new Vector(1, 1, 2))}) as Model;
            cube.setCollision(CollisionStatus.Off);
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Add a key method: press "1" on the keyboard to add or remove ordinary outline to Player Pawn (it will be blocked)
            InputUtil.onKeyDown(Keys.One, () => {
                if(this.flag) {
                    myPlayer.character.setOutline(false);
                } else {
                    myPlayer.character.setOutline(true, LinearColor.red, 1);
                }
                this.flag = !this.flag;
            });
            // Add a button method: Press keyboard "2" to add or remove post-processing strokes for player Pawn (not obscured)
            InputUtil.onKeyDown(Keys.Two, () => {
                if(this.flag_advance) {
                    myPlayer.character.setPostProcessOutline(false);
                } else {
                    myPlayer.character.setPostProcessOutline(true, LinearColor.red, 1);
                }
                this.flag_advance = !this.flag_advance;
            });
        }
    }
}
@Component
export default class Example_Pawn_PostProcessOutline extends Script {
    // Declare variables
    flag: boolean;
    flag_advance: boolean;
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // Set the current stroke status
        this.flag = false;
        this.flag_advance = false;
        // The following code is only executed on the server side
        if(SystemUtil.isServer()) {
            // Create a cube
            let cube = GameObject.spawn("197386",{ transform: new Transform(new Vector(200, 0, 0), Rotation.zero, new Vector(1, 1, 2))}) as Model;
            cube.setCollision(CollisionStatus.Off);
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Add a key method: press "1" on the keyboard to add or remove ordinary outline to Player Pawn (it will be blocked)
            InputUtil.onKeyDown(Keys.One, () => {
                if(this.flag) {
                    myPlayer.character.setOutline(false);
                } else {
                    myPlayer.character.setOutline(true, LinearColor.red, 1);
                }
                this.flag = !this.flag;
            });
            // Add a button method: Press keyboard "2" to add or remove post-processing strokes for player Pawn (not obscured)
            InputUtil.onKeyDown(Keys.Two, () => {
                if(this.flag_advance) {
                    myPlayer.character.setPostProcessOutline(false);
                } else {
                    myPlayer.character.setPostProcessOutline(true, LinearColor.red, 1);
                }
                this.flag_advance = !this.flag_advance;
            });
        }
    }
}