Skip to content

Lucky Engine Scripting

Write C# to drive behaviour in Lucky Engine scenes: move entities, respond to input and collisions, query physics, control robots, and define reinforcement-learning tasks.

  • Getting started

    The scripting model, a first Entity script, and the update lifecycle.

  • Creating and building scripts

    The .NET SDK requirement, creating and attaching scripts, the generated project files, building, and hot reload.

  • Guides

    Task-focused walkthroughs: input, robot control, procedural graph parameters, and recording.

  • API reference

    The public C# scripting API, grouped by area.

A first taste

Every script is a class that derives from Entity. Override the lifecycle methods that matter and call the engine APIs from inside them:

using Hazel;

public class Spinner : Entity
{
    // Public fields appear in the Inspector. See "Editor Attributes" in the reference.
    public float DegreesPerSecond = 90.0f;

    protected override void OnUpdate(float ts)
    {
        // ts is the fixed simulation step, in seconds (0.02 at 50 Hz). Rotation is in radians.
        Rotation += new Vector3(0.0f, DegreesPerSecond * Mathf.Deg2Rad * ts, 0.0f);
    }
}

Attach the compiled script to an entity with a Script component in the editor: add the component, then pick the class in its Script Class field. Once attached, OnUpdate runs every simulation step (50 Hz by default). To generate a new script for an entity in one go, right-click the entity in the viewport and choose Add Script.

Scripts are compiled with the .NET 9 SDK, which you install separately. Creating and building scripts covers the setup, the project files, and the build and reload workflow.

Finding the API reference

The API reference is generated from each release's scripting API, so it always matches the version selected in the header. Use the version selector to switch between engine releases (for example 2026.2 ↔ 2026.3).

From the editor:

  • Help → Scripting API Reference opens the reference for the version you have installed.
  • In the Inspector, the gear menu of most components that scripts can use has Scripting API, which opens that component's page in the reference.

The recording API (Hazel.Data.Observer) is not part of the generated reference. It is covered in Recording with the Observer.