Skip to main content

Accessing entities

There are three ways to access entities from scripts.

Accessing script's entity

All scripts are attached to entities. You can access the entity that the script belongs to using the globally accessible entity object:

local name = entity.name

Querying entities

You can also query entities using the entity query service:

local entityQuery = game:get('EntityQuery')
local foundEntity = entityQuery:getFirstEntityByName("Test")

Spawning entities

You can also spawn entities using the entity spawner service:

local entitySpawner = game:get('EntitySpawner')
local myEntity = entitySpawner:spawnEntity()