ScriptContext API

ScriptContext is passed into most hooks and provides access to the engine, the owning object, and helper APIs.

Core Fields

Field Type Description
engine Engine* Engine pointer
object SceneObject* Owning object (may be null)
script ScriptComponent* Owning script component

Object Lookup

1 SceneObject* obj = ctx.FindObjectByName("Player");
2 SceneObject* obj2 = ctx.FindObjectById(42);

Transform Helpers

1 ctx.SetPosition(400">glm::400">vec3(0, 5, 0));
2 ctx.SetRotation(400">glm::400">vec3(0, 90, 0)); // degrees
3 ctx.SetScale(400">glm::400">vec3(2, 2, 2));
4 ctx.SetPosition2D(400">glm::400">vec2(100, 200)); // UI pixels

UI Helpers (Buttons/Sliders)

1 // Button state
2 400">bool pressed = ctx.IsUIButtonPressed();
3
4 // Interactable state
5 400">bool active = ctx.IsUIInteractable();
6 ctx.SetUIInteractable(400">false); // Make read-only
7
8 // Slider values
9 400">float val = ctx.GetUISliderValue();
10 ctx.SetUISliderValue(0.75f);
11 ctx.SetUISliderRange(0.0f, 100.0f);
12
13 // Label and styling
14 ctx.SetUILabel("Health");
15 ctx.SetUIColor(400">glm::400">vec4(1, 0, 0, 1));
16 ctx.SetUITextScale(1.5f);
17 ctx.SetUISliderStyle(UISliderStyle::Fill);
18 ctx.SetUIButtonStyle(UIButtonStyle::Rounded);
19
20 // Style presets
21 ctx.SetUIStylePreset("Ocean");
22 ctx.RegisterUIStylePreset("Custom", style, 400">true);

Rigidbody Helpers (3D)

1 400">if (ctx.HasRigidbody()) {
2 400">glm::400">vec3 vel;
3 ctx.GetRigidbodyVelocity(vel);
4 ctx.SetRigidbodyVelocity(400">glm::400">vec3(0, 10, 0));
5
6 ctx.AddRigidbodyForce(400">glm::400">vec3(100, 0, 0));
7 ctx.AddRigidbodyImpulse(400">glm::400">vec3(0, 50, 0));
8 ctx.AddRigidbodyTorque(400">glm::400">vec3(0, 1, 0));
9 ctx.AddRigidbodyAngularImpulse(400">glm::400">vec3(0, 5, 0));
10
11 ctx.SetRigidbodyRotation(400">glm::400">vec3(0, 45, 0));
12 ctx.TeleportRigidbody(400">glm::400">vec3(0, 10, 0), 400">glm::400">vec3(0, 0, 0));
13 }

Rigidbody2D Helpers (UI/Canvas)

1 400">if (ctx.HasRigidbody2D()) {
2 400">glm::400">vec2 vel;
3 ctx.GetRigidbody2DVelocity(vel);
4 ctx.SetRigidbody2DVelocity(400">glm::400">vec2(100, 0));
5 }

Audio Helpers

1 400">if (ctx.HasAudioSource()) {
2 ctx.PlayAudio();
3 ctx.StopAudio();
4 ctx.SetAudioLoop(400">true);
5 ctx.SetAudioVolume(0.8f);
6 ctx.SetAudioClip("Assets/Audio/explosion.wav");
7 }

Settings & Utility

1 // String settings
2 std::400">string mode = ctx.GetSetting("mode", "normal");
3 ctx.SetSetting("mode", "hard");
4
5 // Bool settings
6 400">bool enabled = ctx.GetSettingBool("enabled", 400">false);
7 ctx.SetSettingBool("enabled", 400">true);
8
9 // Vec3 settings
10 400">glm::400">vec3 pos = ctx.GetSettingVec3("spawnPos", 400">glm::400">vec3(0));
11 ctx.SetSettingVec3("spawnPos", 400">glm::400">vec3(10, 0, 0));
12
13 // AutoSetting (recommended for inspector UI)
14 400">static 400">bool autoRotate = 400">false;
15 ctx.AutoSetting("autoRotate", autoRotate);
16 ctx.SaveAutoSettings();
17
18 // Console logging
19 ctx.AddConsoleMessage("Hello!", ConsoleMessageType::Info);
20
21 // Mark scene dirty (for saving)
22 ctx.MarkDirty();