Skip to main content

Time

Time.DeltaTime() returns the scaled frame delta in seconds. The deltaTime argument passed to Update and LateUpdate is the same value.

local elapsed = 0.0

function Update(gameObjectId, deltaTime)
elapsed = elapsed + deltaTime
if elapsed >= 2.0 then
Log.Print("Two seconds elapsed")
elapsed = 0.0
end
end

FixedUpdate receives fixedDeltaTime from the bounded 30 Hz simulation step. Do not use a rendered-frame delta for deterministic fixed-step motion.

Time Scale and Pause

Time.SetTimeScale(scale) accepts finite values from 0.0 through 4.0 and returns false when the value is invalid. Time.GetTimeScale() reads the current value. A new scene always begins at 1.0.

At 0.0, scaled gameplay simulation stops: native player controllers, navigation, character motion and collision events, interactions, authored and skeletal animation, timelines, and particles do not advance. Update and LateUpdate still run with deltaTime == 0, and raw Input plus Canvas UI remain active. This lets the same LuaBehaviour close the pause screen.

Time.UnscaledDeltaTime() returns the real frame duration before time scale is applied. Use it only for work that must continue during a pause, such as menu transitions or a UI hold timer.

local menuCanvas = -1
local player = -1
local paused = false

function Awake(gameObjectId)
menuCanvas = Canvas.Find("Pause Menu")
player = GameObject.Find("Player")
end

local function SetPaused(value)
paused = value
Canvas.SetEnabled(menuCanvas, paused)
PlayerInput.SetEnabled(player, not paused)
Time.SetTimeScale(paused and 0.0 or 1.0)
end

function Update(gameObjectId, deltaTime)
if Input.GetButtonDown("Pause") then
SetPaused(not paused)
end
end

PlayerInput.SetEnabled is useful here because it disables native movement and interaction without disabling the Player GameObject, its camera, or its Lua scripts. Raw Input remains available to the menu.