Framework

The client framework is the foundation of Utility Objectify. It provides the class-based system for working with entities and plugins, manages the connection to server-side logic, and enables advanced behavior through decorators.

This page breaks down how the client framework operates and how you can use it to build powerful, modular entity scripts.


🧱 BaseEntity

All object scripts on the client extend the BaseEntity class. This class provides:

You should never instantiate BaseEntity directly. Instead, you define classes that inherit from it.

class Crate extends BaseEntity {
    OnSpawn = function(self)
        print("Crate spawned:", self.id)
    end
}

🪝 Custom Hook System

You can register custom hooks that run on all scripts when objects that define that method are spawned or destroyed.

Example: OnStateChange Hook

RegisterCustomHook("OnStateChange", {
    OnSpawn = function(env, call)
        env.changeHandler = UtilityNet.AddStateBagChangeHandler(env.id, function(key, value)
            call(key, value) -- propagate to the original method
        end)
    end,

    OnDestroy = function(env)
        UtilityNet.RemoveStateBagChangeHandler(env.changeHandler)
    end
})

This will be called only if the currently spawning/destroying entity has a method called OnStateChange The call parameter is a function to invoke the original entity method, triggering the hook call.

Custom hooks can include:

Hook Method
Purpose

exec

Called when ANY script instance is created (also when it doesnt have the specified method name)

OnAwake

Exactly like OnAwake

OnSpawn

Exactly like OnSpawn

AfterSpawn

Exactly like AfterSpawn

OnDestroy

Exactly likeOnDestroy

Then in your entity class just add the hook method

@model("my_model")
class MyEntity extends BaseEntity {
    OnStateChange = function(key, value)
        print("State changed:", key, value)
    end
}

This lets you run custom logic when state changes for any script that implements OnStateChange.


🌐 IsServer / IsClient Flags

To help with shared or conditional logic, Utility Objectify provides two constants:

Constant
Value
Description

IsClient

true

Always true on the client

IsServer

false

Always false on the client


🔎 Framework Functions

SetRPCNamespace(namespace)

Change the prefix used internally for RPC event names by default is Config.Namespace or the current resource name followed by a colon (:)

Server.DisableTimeoutForNext()

Disable the 5s timeout on callbacks for the next RPC call

Last updated