Properties
Entityreturns the owner entity.Transformreturns the owner transform wrapper.Enabledgets or sets whether this script attachment is enabled.
Kroys.EngineScripting
This page documents the public scripting surface available to gameplay code today: lifecycle callbacks, serialized fields, entity handles, transforms, input, time, logging, asset references, scene spawning, and native-backed physics raycasts.
Scripts use Kroys.EngineScripting and usually System.Numerics for vectors and quaternions.
using Kroys.EngineScripting;
using System.Numerics;
[ScriptDisplayName("Gameplay/Keyboard Mover")]
public sealed class KeyboardMover : EntityScript
{
[SerializeField]
[Range(0.0f, 12.0f)]
private float speed = 4.0f;
protected override void OnUpdate(float deltaTime)
{
if (Input.IsKeyDown(KeyCode.W))
{
Transform.Position += Transform.Forward * speed * deltaTime;
}
if (Input.IsKeyDown(KeyCode.S))
{
Transform.Position -= Transform.Forward * speed * deltaTime;
}
}
}
Entity returns the owner entity.Transform returns the owner transform wrapper.Enabled gets or sets whether this script attachment is enabled.OnCreate() runs when the managed instance is created.OnStart() runs when the script starts.OnEnable() and OnDisable() follow enabled-state changes.OnUpdate(float deltaTime) runs during runtime updates.OnDestroy() runs before the instance is destroyed.Public fields are serialized automatically. Private fields need [SerializeField].
| Category | Supported Types |
|---|---|
| Primitive | bool, integers, float, double, string, enums |
| Math | Vector2, Vector3, Vector4, Quaternion, Color |
| References | EntityRef, AssetRef<MaterialAsset>, AssetRef<TextureAsset>, AssetRef<MeshAsset> |
[SerializeField] exposes a private field.[HideInInspector] keeps a serialized field hidden.[ReadOnly] makes an Inspector field read-only.[Range(min, max)] gives numeric fields slider limits.[ScriptDisplayName("Category/Name")] controls editor display.[DefaultExecutionOrder(order)] sets script ordering metadata.[FormerTypeName] and [FormerlySerializedAs] support migration.IsAlive checks whether the native entity still exists.Name returns the entity name.Transform returns a transform wrapper.Destroy() destroys the entity.Position, Rotation, and Scale are local transform values.Forward, Right, and Up are derived from rotation.Scene.Spawn(string name) creates a new entity in the active scene.Input.IsKeyDown(KeyCode) checks whether a keyboard key is currently held.
Time.DeltaTime returns seconds since the previous runtime update.Time.FixedDeltaTime exposes the fixed timestep value.Debug.Log(string)Debug.LogWarning(string)Debug.LogError(string)AssetRef<TAsset> stores a serialized reference to an engine asset and exposes AssetId and IsValid.
using Kroys.EngineScripting;
public sealed class AssetReferencePrinter : EntityScript
{
[SerializeField]
private AssetRef<MaterialAsset> material = default;
protected override void OnCreate()
{
if (material.IsValid)
{
Debug.Log($"Material: {material.AssetId}");
}
}
}
Physics.Raycast queries the active native physics world and returns a RaycastHit on success.
Raycast(origin, direction, distance, out hit)Raycast(origin, direction, distance, out hit, debugDraw)Raycast(origin, direction, distance, out hit, debugDrawDurationSeconds)Raycast(origin, direction, distance, out hit, debugDraw, debugDrawDurationSeconds)Entity hit entity.Point world-space hit point.Normal world-space hit normal.Distance distance from the ray origin.using Kroys.EngineScripting;
using System.Numerics;
public sealed class RayProbe : EntityScript
{
protected override void OnUpdate(float deltaTime)
{
Vector3 origin = Transform.Position + Vector3.UnitY;
Vector3 direction = Transform.Forward;
if (Physics.Raycast(origin, direction, 20.0f, out RaycastHit hit, true, 2.0f))
{
Debug.Log($"Hit {hit.Entity.Name} at {hit.Distance:0.00}m");
}
}
}
using Kroys.EngineScripting;
using System.Numerics;
public sealed class SpawnOnStart : EntityScript
{
protected override void OnCreate()
{
Entity spawned = Scene.Spawn("Runtime Entity");
spawned.Transform.Position = Transform.Position + new Vector3(0.0f, 1.0f, 0.0f);
Debug.Log($"Spawned: {spawned.Name}");
}
}
OnFixedUpdate and OnLateUpdate are present in the managed base class, but the native runtime currently invokes the main lifecycle and OnUpdate path.Input.IsKeyDown(KeyCode).