Basic Structure of a Lua Script

Script Table

Scripts used as components contain a Script Table. The Script Table provides the functionality for the script and is treated like a class. The Script Table generally consists of the following:

  • An optional Properties Table within the Script Table. The Properties Table provides an interface that you can use to customize the script behavior from the editor.

  • An OnActivate() function that the engine calls when the entity that has the script is activated.

  • An OnDeactivate() function called by the engine when the entity that has the script is deactivated.

Skeleton script

The following example shows a skeleton script.

-- ScriptName.lua 

local ScriptName = 
{
    Properties =
    {
        -- Property definitions
    }
}

function ScriptName:OnActivate()
     -- Activation Code
end

function ScriptName:OnDeactivate()
     -- Deactivation Code
end

return ScriptName

Entity Table

For each Lua Script component, O3DE creates a table called the Entity Table. The Script Table in the referenced script is the metatable for the Entity Table. Because of this relationship, when any method in the script is called, the self parameter (implicit in most cases) refers to the Entity Table.

The Entity Table then has the following properties and methods available to it:

  • A Properties table, copied from the Script Table’s Properties Table. Default values are provided where appropriate.

  • An entityId property, which contains an object of type EntityId that refers to the current entity.


Copyright © 2026 DawnEngine. All rights reserved.

DawnEngine is a commercial 3D engine distributed under the DawnEngine end-user license agreement. Engine binaries and source are proprietary and are not covered by the licenses below.

Documentation only: the prose and templates on this site are a derivative work of Open 3D Engine (O3DE) documentation by the O3DE Contributors, used under CC BY 4.0 (documentation content), Apache 2.0 (site code), and the MIT license (inline code samples).

The open-source 3D engine that DawnEngine is built on top of is Open 3D Engine . DawnEngine is not affiliated with, endorsed by, or sponsored by The Linux Foundation or the O3DE project. “O3DE” and “Open 3D Engine” are trademarks of The Linux Foundation.