Object Manipulation

instantiate(objectId, keepParent)

This will duplicate (instantiate) the transform with objectId (transform id), including all its children and components. Depending on keepParent (bool),

  • the duplicate will be a child of the same parent (if nil or true)
  • the duplicate will not have any parent (if false)

The function will return the transform id (int) of the duplicated object.

function instantiate(objectId, keepParent) 

createGameObject(name)

This will create an empty GameObject (including a transform) named name that does not have any parent transform. The function will return the object's transform id (int).

function createGameObject(name) 

destroy(objectId, waitTime)

This will destroy the object with objectId. You can specify a time delay before the object is deleted (using waitTime). If wait time is nil or 0, the object will be deleted at the end of the next update frame. See Object.Destroy in C# for more details.

function destroy(objectId, waitTime) 

destroyImmediate(objectId)

destroyImmediate This will immediately destroy the object with objectId. It will not wait until the end of the frame, the object will already be removed in the next line of lua code.

This may never be called inside any loop that iterates over the children of a transform, e.g. using getChildren, getActiveChildren or getChildrenRecursive as it can lead to undefined behaviour.

function destroyImmediate(objectId) 

setPosition(objectId, x,y,z)

Sets the local position of object with objectId (transform id) relative to its parent to x, y, z (all float).

function setPosition(objectId, x,y,z) 

setRotation(objectId, rx,ry,rz)

Sets the local rotation of object with objectId (transform id) relative to its parent to rx, ry, rz (all float, rotations always in degrees!).

function setRotation(objectId, rx,ry,rz) 

setScale(objectId, sx,sy,sz)

Sets the local scale of object with objectId (transform id) relative to its parent to sx, sy, sz (all float).

function setScale(objectId, sx,sy,sz) 

function getPosition(objectId)

Returns the local position of object with objectId (transformId) as x, y, z (all float).

local x,y,z = getPosition(objectId);

function getRotation(objectId)

Returns the local rotation of object with objectId (transformId) as rx, ry, rz (all float, rotations always in degrees!).

local rx,ry,rz = getRotation(objectId);

function getScale(objectId)

Returns the local scale of object with objectId (transformId) as sx, sy, sz (all float).

local sx,sy,sz = getScale(objectId);

setWorldPosition(objectId, x,y,z)

Sets the world position of object with objectId (transform id) relative to the origin to x, y, z (all float).

function setWorldPosition(objectId, x,y,z) 

setWorldRotation(objectId, rx,ry,rz)

Sets the world rotation of object with objectId (transform id) relative to the origin to rx, ry, rz (all float, rotations always in degrees!).

function setWorldRotation(objectId, rx,ry,rz) 

function getWorldPosition(objectId)

Returns the world position of object with objectId (transformId) as x, y, z (all float).

local x,y,z = getWorldPosition(objectId);

function getWorldRotation(objectId)

Returns the world rotation of object with objectId (transformId) as rx, ry, rz (all float, rotations always in degrees!).

local rx,ry,rz = getWorldRotation(objectId);

function getLossyScale(objectId)

Returns the world scale of object with objectId (transformId) as sx, sy, sz (all float). Check out the Unity Documentation if you are interested in why there is a difference between worldScale and lossyScale.

local sx,sy,sz = getLossyScale(objectId);

function setPositionX, setPositionY, setPositionZ

Sets the respective local position component X, Y or Z (float) for object with objectId (transformId).

This is a shorthand for first getting the position and then setting it, with just one component being changed.

setPositionX(objectId, 0);
setPositionY(objectId, 0);
setPositionZ(objectId, 0);

function setRotationX, setRotationY, setRotationZ

Sets the respective local roation component X, Y or Z (float, always in degrees) for object with objectId (transformId).

This is a shorthand for first getting the rotation and then setting it, with just one component being changed.

setRotationX(objectId, 0);
setRotationY(objectId, 0);
setRotationZ(objectId, 0);

translate(deltaX, deltaY, deltaZ, worldSpace)

Moves an object by a position offset of deltaX, deltaY, deltaZ (all float) in the x, y and z axes respectively, i.e. relative to its current position. Depending on worldSpace (bool),

  • the offset is applied using the object's orientation (false or nil)
  • the offset is applied using the world x, y and z axes (true)
function translate(deltaX, deltaY, deltaZ, worldSpace) 

rotate(deltaX, deltaY, deltaZ, worldSpace)

Rotates an object by an angle of deltaX, deltaY, deltaZ (all float, always in degrees) around the x, y and z axes respectively, i.e. relative to its current position. Depending on worldSpace (bool),

  • the offset is applied using the object's orientation (false or nil)
  • the offset is applied using the world x, y and z axes (true)
function rotate(deltaX, deltaY, deltaZ, worldSpace) 

All contents of this page may be used for modding use for Winter Resort Simulator only. Any use exceeding this regulation is not permitted.

Copyright (C) HR Innoways, 2020. All Rights Reserved.