Entities Singleton
🧠 Entities Singleton
CLIENT for an object to be available in the entities list, it must be rendered.
SERVER always fully populated, allow to access or manipulate any object, no matter where it is in the world.
All live entity instances are tracked in the Entities singleton.
Each object is uniquely identified by its uNetId
</> API Reference
Entities:get(id)
Fetch a object instance from its uNetId
Entities:waitFor(id, timeout? = 5000)
Continuously try to fetch a object instance from its uNetId until found or timeout
Entities:getBy(key, value)
Find an instance by a custom field, value can also be a function working as a filter
Entities:getAllBy(key, value)
Returns a table containing all instances that respect the filter, value can also be a function working as a filter
Entities:createByName(name)
Instantiate a new object of a class with that name
Examples:
local obj = Entities:get(id) -- By unique network ID
local crate = Entities:getBy("type", "Crate") -- By field matchlocal open = Entities:getAllBy("state", function(state) return state.open end)
if open and #open > 0 then
print(open[1].id.." is an open crate")
endlocal specific = Entities:getBy("someCustomId", 100)
if specific then
print(specific.id.." has the attribute someCustomId setted to 100")
endlocal crates = Entities:getAllBy("__type", "Crate")
if crates and #crates > 0 then
print(crates.id.." is a Crate!")
end🔍 Debug & Tracking Tips
You can easily track which objects are active on the server via Entities.list.
Example: list all crates currently spawned:
for _, obj in pairs(Entities.list) do
if obj is Crate then
print("Active crate:", obj.id)
end
endLast updated