Collider:setUserData

Edit

Associates a Lua value with the Collider.

Collider:setUserData(data)

Arguments

NameTypeDescription
data* The custom value to associate with the Collider.

Returns

Nothing

Notes

Set the user data to nil to clear any existing reference.

The userdata is useful for linking a Collider with custom data:

local collider = world:raycast(origin, direction, 'enemy')

if collider then
  -- Get the enemy object from its Collider
  local enemy = collider:getUserData()
  enemy.health = 0
end

The user data is not shared between threads. Each thread has its own user data for the Collider.

See also