Object Management
This page explains how object scripts are created, registered, managed, and destroyed dynamically on the client.
Utility Objectify includes a powerful system for managing object script instances tied to entities in the world.
When entities are spawned or unspawned, the framework dynamically creates or destroys script instances based on model-to-class mappings. This allows for automatic behavior assignment and modular logic.
🧠 How It Works
OnRender
When an entity becomes visible to the player:
Its model is checked against registered scripts.
A new instance of the class extending
BaseEntity
is created for each script (main
and any plugins).Is added to the global 🧠 Entities Singleton list.
Lifecycle methods (OnAwake, OnSpawn, AfterSpawn) are called.
The instance is stored and tracked.
OnUnrender
When the entity is no longer visible:
OnDestroy is called on each script.
It remove itself from the 🧠 Entities Singleton list
All associated script instances are destroyed.
Object memory is freed.
This logic is handled via internal UtilityNet events:
UtilityNet.OnRender(...) -- Creates script instances
UtilityNet.OnUnrender(...) -- Destroys script instances
📦 Temp Object Properties
Before the object is rendered, properties set during OnRegister are stored in a temporary table:
self.someData = 123
These are stored and later injected to the real instance when the object is rendered. This ensures that OnRegister can prepare data even before the object is visible, like creating a blip at the entity coords
can interact only with the temporary instance properties, not real instance runtime changed properties.
have access only to self.id
and self.state
can interact with the temporary instance properties, as they will be injected before the OnAwake hook
🔎 Object Management Functions
IsObjectScriptRegistered(model, name)
Checks if a specific model as a script registered to im, can be useful if a plugin needs another plugin to work properly
RegisterCustomHook(hookMethod, hookData)
GetObjectScriptInstance(obj, name, nocheck?)
Fetch a specific script instance by name from an object.
All main scripts are exposed as main
nocheck = true
skips rendering checks.
GetExternalObjectScriptStatic(model, name)
Returns the raw script table (class) without creating an instance.
⚠️ This is unsafe for live operations, use for inspection only.
AreObjectScriptsFullyLoaded(obj)
Returns true
if all scripts have been fully created and attached to the object.
Last updated