Skip to content

Custom Scripts

Adrien Givry edited this page Feb 7, 2025 · 1 revision

Creating a script

Every scripts in Overload are behaviours, meaning that when creating a script, your custom usertype will get interpreted by the engine as a behaviour that can be attached to any Actor.

In order to create a script, right click onto the Scripts folder in the Asset Browser window, click onto "New script...", enter a name and click enter.

image

Implementing your own behaviour

In order to create gameplay interactions in your scripts, you'll need to implement some of these functions:

Name Input Output Description
OnAwake Usertype: instance
Called when the scene start right before OnStart
OnStart Usertype: instance
Called when the scene start right after OnAwake
OnEnable Usertype: instance
Called when the behaviour gets enabled (owner SetActive set to true)
OnDisable Usertype: instance
Called when the behaviour gets disabled (owner SetActive set to false)
OnDestroy Usertype: instance
Called when the behaviour gets destroyed
OnUpdate Usertype: instance
number: deltaTime
Called every frame
OnFixedUpdate Usertype: instance
number: fixedDeltaTime
Called every physics frame
OnLateUpdate Usertype: instance
number: deltaTime
Called every frame after OnUpdate
OnCollisionEnter Usertype: instance
PhysicalObject: collideWith
Called when the owner of this behaviour enter in collision with another physical object
OnCollisionStay Usertype: instance
PhysicalObject: collideWith
Called when the owner of this behaviour is in collision with another physical object
OnCollisionExit Usertype: instance
PhysicalObject: collideWith
Called when the owner of this behaviour exit from collision with another physical object
OnTriggerEnter Usertype: instance
PhysicalObject: triggeredBy
Called when the owner of this behaviour enter in trigger with another physical object
OnTriggerStay Usertype: instance
PhysicalObject: triggeredBy
Called when the owner of this behaviour is in trigger with another physical object
OnTriggerExit Usertype: instance
PhysicalObject: triggeredBy
Called when the owner of this behaviour exit from trigger with another physical object

Example

-- Holds data that are shared between functions of this usertype
local MoveUpDown =
{
    elapsed = 0
}

-- Called when the scene starts
function MoveUpDown:OnStart()
end

-- Called every frame (The passed deltaTime holds the time elapsed between the current and previous frame in seconds)
function MoveUpDown:OnUpdate(deltaTime)
    -- Here, elapsed is incremented to sum the elapsed time since start
    self.elapsed = self.elapsed + deltaTime

    -- Stores the transform component instance into a variable
    transform = self.owner:GetTransform()

    -- Invoke SetPosition function with `:` to send the transform instance as first parameter to this function
    -- `transform:SetPosition(...)` is equivalent to `transform.SetPosition(transform, ...)`
    transform:SetPosition(Vector3.new(0, math.sin(self.elapsed), 0))

end

-- Returns the usertype so the engine has a reference to it
return MoveUpDown
Clone this wiki locally