Object Management
🧠 How It Works
On the server, object scripts are instantiated manually or programmatically using Lua class instantiation. These scripts are tightly integrated with networked entities created via UtilityNet
.
When You Create a Server Entity
Class extending
BaseEntity
is instantiated (e.g.new MyEntity(coords?, rotation?, options?)
)UtilityNet.CreateEntity(...)
is called under the hood.The entity is given a
uNetId
, synced state, and added to the global 🧠 Entities Singleton list.All plugins (declared via @plugin(pluginName)) are attached and initialized.
Lifecycle methods are triggered in the following order:
constructor → create() [Only if coords is passed] → init() → OnAwake → OnSpawn → AfterSpawn
When You Destroy an Entity
Calling self:destroy()
on a server entity will:
Remove it from the 🧠 Entities Singleton list
Call the OnDestroy lifecycle hook (if defined)
Call
UtilityNet.DeleteEntity(...)
to remove the object from the world
The client will automatically respond to this removal and clean up its instances.
🔁 No Render-Based Logic
Unlike the client, the server does not rely on OnRender
/ OnUnrender
logic:
Render Detection
❌
✅
Object Lifetime
Manual
Auto (on render)
Memory Cleanup
Explicit
Auto (on unrender)
All object creation and destruction is fully controlled by your server-side logic.
🧰 UtilityNet Integration
Utility Objectify relies on UtilityNet
for:
Creating synced entities
Managing state (
self.state
)Getting/setting entity IDs (
self.id
)Deleting objects
Resolving object existence (
UtilityNet.DoesUNetIdExist(id)
)
You must load
utility_lib
beforeutility_objectify
or the server will throw an error.
Last updated