C++ Scripting Quickstart

Scripts in Modularity are native C++ code compiled into shared libraries and loaded at runtime. They run per scene object and can optionally draw ImGui UI in the inspector and in custom editor windows.

Important Notes

  • Scripts are not sandboxed. They can crash the editor/game if they dereference bad pointers or do unsafe work.
  • Always null-check ctx.object — objects can be deleted, disabled, or scripts can be detached.

Getting Started

  1. 1 Create a script file under Scripts/ (e.g. Scripts/MyScript.cpp)
  2. 2 Select an object in the scene
  3. 3 Add/enable a script component in the Inspector — set the Path or click Use Selection
  4. 4 Compile the script — right-click in File Browser → Compile Script
  5. 5 Implement a tick hook (TickUpdate) and observe behavior in play mode

Minimal Script Example

Scripts/MyScript.cpp CPP
1 400">class="text-violet-400">#include "ScriptRuntime.h"
2
3 400">void TickUpdate(400">ScriptContext& ctx, 400">float /*dt*/) {
4 400">if (!ctx.object) 400">return;
5 // Your frame logic here
6 }

Script with Inspector UI

Scripts/InspectorScript.cpp CPP
1 400">class="text-violet-400">#include "ScriptRuntime.h"
2 400">class="text-violet-400">#include "ThirdParty/imgui/imgui.h"
3
4 400">void TickUpdate(400">ScriptContext& ctx, 400">float /*dt*/) {
5 400">if (!ctx.object) 400">return;
6 }
7
8 400">extern "C" 400">void Script_OnInspector(400">ScriptContext& ctx) {
9 400">ImGui::TextDisabled("Hello from inspector!");
10 (400">void)ctx;
11 }

Next Steps