Options
All
  • Public
  • Public/Protected
  • All
Menu

Class StaticObject

An object in the game. This class only contains methods and attributes that all objects share, whether they are interactive and physically simulated or not. For most purposes, the derived class GameObject is used. Static objects are used when interacting with tables from scripts.

Hierarchy

Index

Properties

onSnappedTo

onSnappedTo: MulticastDelegate<(object: GameObject, player: Player, snapPoint: SnapPoint, grabPosition: Vector | [x: number, y: number, z: number], grabRotation: Rotator | [pitch: number, yaw: number, roll: number]) => void>

Called when another object is snapped to a snap point on this object. This event is triggered for the object with the target snap point, see GameObject.onSnapped for an event on the object that snaps.

param

The object being released

param

The player that released the object

param

The point that the object is moved to

param

The position where the released object was when it was grabbed. Zero if it hasn't been grabbed (for example when it was dragged from the object library)

param

The rotation the released object had when it was grabbed.

Methods

addDrawingLine

  • Add a drawn line to the object. Lines are geometry and can increase the size of the object returned by getSize and getExtent. Returns whether the line was added successfully. It can't be added if no table exists, if the DrawingLine is invalid, or if there are already too many lines drawn on the table and the new line would go beyond the limit.

    Parameters

    Returns boolean

addUI

  • Attach a new UI element object to this object.

    Parameters

    • element: UIElement

      The UI element to attach

    Returns number

    • The index of the attached UI element

attachUI

  • deprecated

    alias for addUI

    Parameters

    • element: UIElement

      The UI element to attach

    Returns number

    • The index of the attached UI element

destroy

  • destroy(): void

getAllSnapPoints

getAttachedUIs

getBounciness

  • getBounciness(): number
  • Return the object's bounciness value

    Returns number

getDensity

  • getDensity(): number
  • Return the object's density value

    Returns number

getDescription

  • getDescription(): string
  • Return the object's description

    Returns string

getDrawingLines

getExtent

  • getExtent(currentRotation: boolean, includeGeometry: boolean): Vector
  • Get the object extent: half-size of an axis-aligned bounding box encompassing the object. Adding this vector to the position returned by getExtentCenter gives a corner of the bounding box.

    Parameters

    • currentRotation: boolean

      If true, return the extent of an axis-aligned bounding box around the object at its current rotation. If false, return for the default rotation.

    • includeGeometry: boolean

      Determines whether visible geometry is included in the extent. If false, only colliders are used when determining the extent.

    Returns Vector

getExtentCenter

  • getExtentCenter(currentRotation: boolean, includeGeometry: boolean): Vector
  • Get the center of the object extent: an axis-aligned bounding box encompassing the object. This will often be the same position as returned by getPosition, but will differ for objects with their physical center not at their volume center.

    Parameters

    • currentRotation: boolean

      If true, return the extent of an axis-aligned bounding box around the object at its current rotation. If false, return for the default rotation.

      • @param {boolean} includeGeometry - Determines whether visible geometry is included in the extent. If false, only colliders are used when determining the extent.
    • includeGeometry: boolean

    Returns Vector

getFriction

  • getFriction(): number
  • Return the object's friction value

    Returns number

getId

  • getId(): string

getMetallic

  • getMetallic(): number
  • Return the object's metallic value.

    Returns number

getName

  • getName(): string
  • Return the object's user visible name

    Returns string

getPackageId

  • getPackageId(): string
  • Return the id of the package that the object's template belongs to

    Returns string

getPackageName

  • getPackageName(): string
  • Return the name of the package that the object's template belongs to

    Returns string

getPosition

getPrimaryColor

  • getPrimaryColor(): Color

getRotation

getRoughness

  • getRoughness(): number
  • Return the object's roughness value. Lower roughness makes the object more shiny.

    Returns number

getSavedData

  • getSavedData(key: string): string
  • Return data that was stored using setSavedData or loaded from a saved state.

    Parameters

    • key: string

    Returns string

getScale

getScriptFilename

  • getScriptFilename(): string
  • Return the filename of the object's script. Returns an empty string if no script is set for the object.

    Returns string

getScriptPackageId

  • getScriptPackageId(): string
  • Return the package id of the object's script. Returns an empty string if no script is set for the object.

    Returns string

getSecondaryColor

  • getSecondaryColor(): Color

getSize

  • Get the size of the object in cm. This is the same size that is shown in the editor and the coordinates window, it doesn't change when the object is rotated. If you are looking to calculate the borders of the object, use getExtent instead.

    Returns Vector

getSnapPoint

  • getSnapPoint(index: number): SnapPoint | undefined
  • Return a snap point of the object

    Parameters

    • index: number

      Index of the snap point

    Returns SnapPoint | undefined

getSurfaceType

  • getSurfaceType(): string
  • Return surface type. Only affects sound effects when colliding with other objects.

    Returns string

getTags

  • getTags(): string[]
  • Return the current list of tags for the object.

    Returns string[]

getTemplateId

  • getTemplateId(): string
  • Return the object's template id

    Returns string

getTemplateMetadata

  • getTemplateMetadata(): string
  • Return the metadata of the object's template (set in the editor). Can contain JSON encoded information.

    Returns string

getTemplateName

  • getTemplateName(): string
  • Return the name of the object's template

    Returns string

getUIs

isValid

  • isValid(): boolean
  • Return whether the object is valid. An object becomes invalid after it has been destroyed

    Returns boolean

localPositionToWorld

  • localPositionToWorld(position: Vector | [x: number, y: number, z: number]): Vector
  • Transform an object position to a world position

    Parameters

    • position: Vector | [x: number, y: number, z: number]

      The position relative to the object center to transform to world space

    Returns Vector

localRotationToWorld

  • localRotationToWorld(rotation: Rotator | [pitch: number, yaw: number, roll: number]): Rotator
  • Transform an object rotation to a world rotation

    Parameters

    • rotation: Rotator | [pitch: number, yaw: number, roll: number]

      The rotation relative to the object center to transform to world space

    Returns Rotator

removeDrawingLine

  • removeDrawingLine(index: number): void
  • Remove the drawn line at the given index from the object

    Parameters

    • index: number

    Returns void

removeDrawingLineObject

removeUI

  • removeUI(index: number): void
  • Remove attached UI element at the given index.

    Parameters

    • index: number

      The index of the UI element to remove

    Returns void

removeUIElement

  • Remove an attached UI element. Does not have any effect if the passed UI element is not attached to the object.

    Parameters

    Returns void

setBounciness

  • setBounciness(bounciness: number): void
  • Set the object's bounciness value

    Parameters

    • bounciness: number

      The new bounciness value, from 0 to 1

    Returns void

setDensity

  • setDensity(density: number): void
  • Set the object's density value

    Parameters

    • density: number

      The new density value

    Returns void

setDescription

  • setDescription(description: string): void
  • Set the object's description

    Parameters

    • description: string

      The new object description. Maximum length is 2000 characters. You can use the same BBCode tags as in the in-game notes or the RichText widget.

    Returns void

setFriction

  • setFriction(friction: number): void
  • Set the object's friction value

    Parameters

    • friction: number

      The new friction value, from 0 to 1

    Returns void

setId

  • setId(iD: string): boolean
  • Set the object's unique id. Returns whether the id was changed successfully. Fails if the id is already used by another object.

    Parameters

    • iD: string

    Returns boolean

setMetallic

  • setMetallic(metallic: number): void
  • Set the object's metallic value

    Parameters

    • metallic: number

      The new metallic value, from 0 to 1

    Returns void

setName

  • setName(name: string): void
  • Set the object's user visible name

    Parameters

    • name: string

      The new name

    Returns void

setPosition

  • setPosition(position: Vector | [x: number, y: number, z: number], animationSpeed?: number): void
  • Set the object's position. Optionally show an animation of the object flying toward the new location. The animation is only visual, the physical location of the object is changed instantly. Does not have an effect if a player is currently holding the object.

    Parameters

    • position: Vector | [x: number, y: number, z: number]

      The new position

    • Optional animationSpeed: number

      If larger than 0, show animation. A value of 1 gives a reasonable, quick animation. Value range clamped to [0.1, 5.0]. Default: 0

    Returns void

setPrimaryColor

  • setPrimaryColor(color: Color | [r: number, g: number, b: number, a: number]): void
  • Set the object's primary color

    Parameters

    • color: Color | [r: number, g: number, b: number, a: number]

      The new primary color

    Returns void

setRotation

  • setRotation(rotation: Rotator | [pitch: number, yaw: number, roll: number], animationSpeed?: number): void
  • Set the object's rotation. Optionally show an animation of the object rotating toward the new orientation. The animation is only visual, the physical rotation of the object is changed instantly. Does not have an effect if a player is currently holding the object.

    Parameters

    • rotation: Rotator | [pitch: number, yaw: number, roll: number]

      The new rotation

    • Optional animationSpeed: number

      If larger than 0, show animation. A value of 1 gives a reasonable, quick animation. Value range clamped to [0.1, 5.0]. Default: 0

    Returns void

setRoughness

  • setRoughness(roughness: number): void
  • Set the object's roughness value. Lower roughness makes the object more shiny.

    Parameters

    • roughness: number

      The new roughness value, from 0 to 1

    Returns void

setSavedData

  • setSavedData(data: string, key: string): void
  • Set the data that will be stored in save game states. The data is available using getSavedData when the object script is run after loading a save state. Try to keep this data small and don't change it frequently, it needs to be sent over the network to all clients. A similar method exists for global saved data: GameWorld.setSavedData.
    If you want to use custom data that is not a string, you can encode it to JSON using JSON.stringify(), and then decode what you get from getSavedData using JSON.parse().

    Parameters

    • data: string

      Data to store, maximum length 1023 characters

    • key: string

    Returns void

setScale

  • setScale(scale: Vector | [x: number, y: number, z: number]): void
  • Set the object's scale instantly

    Parameters

    • scale: Vector | [x: number, y: number, z: number]

      The new scale

    Returns void

setScript

  • setScript(filename: string, packageId?: string): void
  • Set the object's script. The script will be executed immediately.

    Parameters

    • filename: string

      The filename of the script. Pass an empty string to remove the current script.

    • Optional packageId: string

      The id of the package that contains the script file (in the Scripts folder). Can usually be empty when used from scripts to use the same package that contains the script file, but you need to explicitly pass refPackageId for the current package or a package id when you use it in a callback. You can find package ids in the manifest.json file in package folders. Usually you won't use this parameter, unless you have a specific reason to set a script from a different package than where the calling script is located.

    Returns void

setSecondaryColor

  • setSecondaryColor(color: Color | [r: number, g: number, b: number, a: number]): void
  • Set the object's secondary color

    Parameters

    • color: Color | [r: number, g: number, b: number, a: number]

      The new secondary color

    Returns void

setSurfaceType

  • setSurfaceType(surfaceType: string): void
  • Set surface type. Only affects sound effects when colliding with other objects.

    Parameters

    • surfaceType: string

    Returns void

setTags

  • setTags(tags: string[]): void
  • Set the list of tags for the object.

    Parameters

    • tags: string[]

    Returns void

setUI

  • setUI(index: number, element: UIElement): void
  • Replace an attached UI element. Will not do anything if called with an index that doesn't have a UI element.

    Parameters

    Returns void

toJSONString

  • toJSONString(): string
  • Return a Json string representing the object. Can be used to spawn copies.

    Returns string

updateUI

  • Update an attached UI element. Will not do anything if called with a UI element that is not attached to the object. You need to call this method after modifying values in a UIElement. Does not work if you change the UIElement.widget property, you have to use setUI in this case.

    Parameters

    Returns void

worldPositionToLocal

  • worldPositionToLocal(position: Vector | [x: number, y: number, z: number]): Vector
  • Transform a world position to an object position

    Parameters

    • position: Vector | [x: number, y: number, z: number]

      The position in world space to transform to relative to the object

    Returns Vector

worldRotationToLocal

  • worldRotationToLocal(rotation: Rotator | [pitch: number, yaw: number, roll: number]): Rotator
  • Transform a world rotation to an object rotation

    Parameters

    • rotation: Rotator | [pitch: number, yaw: number, roll: number]

      The rotation in world space to transform to relative to the object

    Returns Rotator

Static getExecutionReason

  • getExecutionReason(): string
  • Used when executing an object script to determine why it was executed. Possible return values:
    "Create" - The object was newly created, for example from the object library or through copy and paste
    "ScriptReload" - The script was reloaded, for example because it was set on the object for the first time, or because the scripting environment was reset
    "StateLoad" - A game state that contained the object was loaded

    Returns string