Skip to content

Scripting overview

C# scripts run your gameplay. The engine hosts the .NET 10 runtime and calls your MonoBehaviour methods automatically.

You write scripts as classes in the Kolpa.Demo assembly under bindings/Kolpa.Demo/. Each script derives from Kolpa.Engine.MonoBehaviour.

Shipped bindings/Kolpa.Demo/ is sample code. Use it, copy it, modify it, or delete it. It is up to you.

The engine creates one instance per Script component and calls these methods if you override them:

Method When Typical use
OnCreate Once, when the Script component is attached Cache references, add components, read fields
OnUpdate(float deltaTime) Every frame, deltaTime in seconds Movement, input, per-frame logic
OnTriggerEnter / OnTriggerExit Physics sensor overlap begins or ends Pickups, doors, zones
OnDestroy When the component is removed, on hot reload, on shutdown Cleanup

Implement only the methods you need.

using Kolpa.Engine;
public class Rotator : MonoBehaviour
{
public float Speed = 45f;
public override void OnUpdate(float deltaTime)
{
transform.Rotate(0f, Speed * deltaTime, 0f);
}
}
  1. Select the GameObject in the Scene Hierarchy.
  2. In the inspector, Add Component -> Script.
  3. In the Behaviour field, type the assembly-qualified type name, for example Kolpa.Demo.Rotator, Kolpa.Demo.

The Script inspector shows one Behaviour field. To change config values, set the public fields in the script or from another script. Do not expect per-field inspector widgets.

Scripts compile into Kolpa.Demo.dll. In play mode, the engine loads the assembly and can hot reload it.

  1. Edit your .cs file under bindings/Kolpa.Demo/.
  2. Build with the project build tool. See the engine README.md for the build and test-scripting commands.
  3. Use Debug -> Reload Assets to reload the managed assembly without restarting.

Note: Hot reload is unavailable in a NativeAOT release build. Scripts there are compiled into the binary.

  • The API uses Scene, not world. SceneManager loads, saves, and switches scenes.
  • Gameplay objects are GameObject, never “entity”. The storage backend uses entities internally, but that never appears in scripts or docs.

Previous: Kolpa Engine Manual: manual home.

Next: Editor setup: VS Code, the C# extension, and the engine API.