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.
Lifecycle
Section titled “Lifecycle”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); }}Attaching a script
Section titled “Attaching a script”- Select the GameObject in the Scene Hierarchy.
- In the inspector, Add Component -> Script.
- 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.
Build and reload
Section titled “Build and reload”Scripts compile into Kolpa.Demo.dll. In play mode, the engine loads the assembly and can hot reload it.
- Edit your
.csfile underbindings/Kolpa.Demo/. - Build with the project build tool. See the engine
README.mdfor thebuildandtest-scriptingcommands. - 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.
Important terms
Section titled “Important terms”- The API uses Scene, not world.
SceneManagerloads, saves, and switches scenes. - Gameplay objects are
GameObject, never “entity”. The storage backend uses entities internally, but that never appears in scripts or docs.
Continue reading
Section titled “Continue reading”Previous: Kolpa Engine Manual: manual home.
Next: Editor setup: VS Code, the C# extension, and the engine API.
