The C# API¶
What a script sees, by topic. The types live in Conjure.Managed (namespace Conjure); the native entries
behind them are declared by conjure/bindings/native_api_entries.h and counted by
conjure/bindings/call_counters.h. Your game project references Conjure.Managed.dll. The editor's script.create
writes scripts/Game.csproj from the engine's template, managed/Conjure.Templates/Game/Game.csproj, when your
project has none. ConjureManagedDir names the folder that holds the DLL: the managed folder beside
conjure_editor (bin/managed in an engine build). Conjure.Managed.xml beside the DLL gives your IDE the API's
summaries; an exported game leaves it out.
| Name | The C# API |
| Module | Bindings |
#include |
conjure/bindings/call_counters.h, conjure/bindings/native_api_entries.h |
| Engineering Handbook | Engineering handbook |
Syntax¶
Usage and complete examples are described in the reference sections below.
At a glance¶
| You want to... | Use |
|---|---|
| Create, find, destroy an entity | Entity.Create(name), Entity.Find(name), Entity.FindByGuid, FindByTag, FindByLayer, entity.Destroy() |
| Move something | Transform.Position / Rotation / Scale / Local / World, Translate, Rotate, LookAt |
| Parent and children | Transform.SetParent(parent, keepWorld, index), Transform.Parent, GetChildren(span), Entity.Root |
| Read or write a native component | GetComponent<T>(), SetComponent(in value), AddComponent, RemoveComponent, HasComponent, TryGetComponent |
| Apply forces, move a kinematic body | new Rigidbody(entity).AddForce(force, mode), AddTorque, MoveKinematic, Teleport, LinearVelocity |
| Walk a character | new CharacterController(entity).Move(velocity), IsGrounded, Velocity |
| Query the world | Physics.Raycast, RaycastAll, SphereCast, BoxCast, CapsuleCast, OverlapSphere, OverlapBox, Physics.Gravity, LayerMask |
| Play a sound | new AudioSource(entity).Play(), Stop, Pause, Volume, Pitch, Loop, Clip; Audio.PlayOneShot, MasterGain, group gains |
| Read input | Input.IsKeyDown / Pressed / Released, MousePosition, MouseDelta, gamepads, Input.CursorMode, Input.Clipboard |
| Spawn a prefab, load a scene | Prefab.Find(path).Instantiate(parent), InstantiateMany, Scene.Load(path, additive), Scene.Unload, Scene.IsLoaded |
| Reference an asset | AssetRef<T>: Load, LoadBlocking, Release, IsLoaded, State, AssetRef<T>.Find(path) |
| Set the anti-aliasing from an options menu | Rendering.AntiAliasing = new AntiAliasingSettings { ... }, Rendering.SupportedMsaaSampleCounts |
| Report a self-check, read frame statistics | Diagnostics.Check(name, passed, detail), Diagnostics.Stats, Diagnostics.LastError |
| See which modules are loaded | Modules.Registry (read-only ModuleInfo list) |
| Iterate thousands of components without per-entity calls | ComponentQuery.Begin<T1, T2>(), NextChunk, ChunkView.Get<T>(column) |
Variables and Properties¶
Types, fields, and state are described in the reference sections below.
Scripts and their lifecycle¶
A script is a class deriving from ScriptBehaviour. The engine instantiates it when its entity gets the
script component (from a scene file, a prefab or entity.AddScript<T>()) and calls, in order, OnCreate (once,
also after a hot reload), OnStart (once, before the first OnFixedUpdate, OnUpdate or OnLateUpdate), then
per fixed step OnFixedUpdate, per frame OnUpdate and OnLateUpdate, and OnDestroy when the entity or the
script goes away. A script created during OnUpdate therefore skips that frame's OnLateUpdate: its OnStart
runs at the next fixed step or update, its first OnLateUpdate after that. Collision callbacks
(OnCollisionEnter(in Collision), OnCollisionExit(in Collision), OnTriggerEnter(Entity other),
OnTriggerExit(Entity other)) deliver the contacts of the previous fixed step, one step after they happened.
OnCollisionExit also arrives when the last awake body of a solid pair falls asleep, and OnCollisionEnter again
when it wakes; OnTriggerExit of a static trigger arrives only when the body really leaves
(triggers).
An exit caused by destroying the other entity still names it, although it is no longer alive (and, one step
later, any other may have been destroyed since): check other.IsAlive (collision.Other.IsAlive) before
touching it. The handle never matches an entity created later, so a script that tracks occupants by entity can
use it to remove the right one.
Entity, Transform, GetComponent<T>(), HasComponent<T>() and Destroy() are available on the base class.
Public fields and [SerializeField] private fields are saved with the scene, shown in the inspector
([Range], [Tooltip], [HideInInspector]) and preserved across hot reloads; everything else resets. An enum
field is stored as a 32-bit integer, so an enum backed by long or ulong is not serialised (an INFO log names
the field). JSON has no NaN or infinity: a NaN default is stored as 0 and an infinite one as the largest finite
value of its type (an INFO log names the field), and a [Range] bound that is not finite leaves that side open.
Serialised string, List<T> and array fields are never null once the script is created or reloaded: null is
saved as "" or as an empty collection, so it comes back that way after a hot reload, a scene load or entering
play mode (the Unity rule). Initialise collections in the field initialiser and test Count or Length, not
null.
public sealed class Spinner : ScriptBehaviour
{
[Range(0.0, 720.0)] public float DegreesPerSecond = 90.0f;
protected override void OnUpdate(float deltaTime)
{
Transform transform = Transform;
transform.Rotate(Quaternion.CreateFromAxisAngle(Vector3.UnitY, DegreesPerSecond * deltaTime * MathF.PI / 180.0f));
}
}
Warning
Transform, Rigidbody, AudioSource and the other facades are readonly structs returned by value. Write
Transform transform = Transform; transform.Position = p; — Transform.Position = p does not compile (CS1612),
and a property setter on a temporary would be lost anyway.
Entities, transforms and the hierarchy¶
Entity is an 8-byte handle (Id, IsNull, IsAlive, Name). Entity.Create(name) makes a scene entity with
a transform and a guid; Destroy() queues it for the end of the phase (OnDestroy sees the entity alive).
Transform reads and writes LocalTransform and the world pose: Position, Rotation, Scale and Local
(one call each way), World and WorldMatrix, Forward, Right, Up, Translate, Rotate, LookAt,
Interpolated (the physics-interpolated pose the renderer draws). The hierarchy half: Parent,
SetParent(parent, keepWorld = true, index = -1), ChildCount, GetChildren(Span<Entity>), Entity.Root,
Enabled, Tag, HasTag, Layer, Guid, Duplicate(), Entity.CreateMany(count, span, parent).
Tip
Position is a get or a set, one native call each. For a batch of entities use Local once per entity, or a
ComponentQuery over LocalTransform and write the spans.
Components and mirrors¶
A [NativeComponent("conjure.scene.local_transform")] struct mirrors a native component field for field;
the size and layout hash are checked against the native registry the first time the mirror is used, and again
after every runtime re-initialisation (ComponentType<T>). A mismatch is logged and never cached: HasComponent,
GetComponent, TryGetComponent, AddComponent, SetComponent, RemoveComponent and ComponentQuery.Begin
then throw InvalidOperationException naming the struct. The assembly itself loads, so a stale mirror fails when
a script first touches it, not at start-up. The mirrors shipped:
LocalTransform, WorldTransform, InterpolatedTransform, Parent, Name, Tag, Layer, EntityGuid,
Disabled, TransformDirty, PrefabInstance (scene); RigidBodyData, BoxColliderData, SphereColliderData,
CapsuleColliderData, ConvexColliderData, MeshColliderData, PhysicsMaterialData, CharacterControllerData
(physics); AudioSourceData, AudioListenerData (audio). GetComponent<T>() copies the struct out,
SetComponent(in value) copies it back, AddComponent / RemoveComponent change the archetype at once outside a
query scope and at the end of the phase inside one. A struct of your own marked [EcsComponent] becomes a
dynamic ECS component the editor can show and scene files can save. Its fields may be bool, the integers,
float, double, Vector2/3/4, Quaternion, Matrix4x4, TransformData, Entity / EntityHandle,
StringId, AssetId, NativeBool or an enum (stored as its underlying integer); a struct with an AssetRef<T>
or a nested struct field is skipped at load with a warning naming the field. Every field counts, including one
named like mirror padding (Pad1): only a [NativeComponent] mirror treats Pad<digits> fields as padding.
Caution
WorldTransform, InterpolatedTransform and the [runtime] fields of RigidBodyData (velocities,
IsSleeping) are written by the engine every frame. Writing them back with SetComponent is overwritten at
the next step; use Transform, Rigidbody and the facades to change state.
Physics, audio, input¶
Rigidbody (over RigidBodyData): LinearVelocity, AngularVelocity, AddForce(force, ForceMode),
AddForceAtPosition, AddTorque, MoveKinematic(in TransformData), Teleport, IsSleeping, WakeUp.
ForceMode is Force, Impulse, VelocityChange or Acceleration, mapped with the body's mass.
A request the body's kind cannot take throws ArgumentException: AddForce, AddForceAtPosition and AddTorque
on a body that is not dynamic, a velocity setter on a static body, MoveKinematic on anything but a kinematic body
without KINEMATIC_MOVES_WITH_TRANSFORM, and all of these on an entity that also has a character controller.
Teleport works on every kind and WakeUp does nothing on a static body. A body created since the last fixed
step accepts every request and drops, with a count, what it cannot take.
CharacterController: Move(velocity), IsGrounded, Velocity. Both velocities are the character's own: the
step adds the horizontal velocity of the ground that carries a grounded character, so on a moving platform
Move(Vector3.Zero) stands still on the platform, Velocity reads zero there, and a jump keeps the platform's
speed until the character touches ground again. Only the horizontal part is carried; on a lift that rises, or
sinks slower than 0.1 m/s, the vertical part of Velocity reads the lift's. On a lift that sinks faster it is
left unchanged (zero for a character that stands still) and CharacterFlags.StickToFloor steps the character
down after the lift, one step of the lift's motion behind
(the character controller). The static Physics
class queries the world:
Raycast(origin, direction, maxDistance, out RaycastHit, LayerMask), RaycastAll, the shape casts,
OverlapSphere, OverlapBox, Gravity (get and set), Layer(name), LayerIndex, LayerName, LayersCollide.
A query without a mask tests every layer; a mask you pass is used as given, so LayerMask.None (or a computed
empty mask) hits nothing. Every query, ray, cast or overlap, skips trigger volumes and includes static bodies;
C# cannot change either (the native query_filter flags are not exposed yet). maxDistance must be finite and
non-negative (ArgumentException otherwise); there is no infinite ray, pass a world-sized distance.
A layer index outside the project's layer table throws KeyNotFoundException from LayerName and LayersCollide
alike. Setting LinearVelocity or AngularVelocity, or calling CharacterController.Move, changes the value the
matching getter reads only when the physics world accepted the request: a refused one (a non-finite vector, a full
command queue, a body of a kind the request does not apply to) throws and leaves the old value in place.
AudioSource plays the clip of an audio_source component: Play, Stop, Pause, Resume, IsPlaying,
Volume, Pitch, Loop, Clip. The static Audio class offers PlayOneShot(clip, position, volume, group),
MasterGain, GetGroupGain / SetGroupGain and ClipDuration. Playback requests are consumed by the engine's
engine.audio_sync system in the same frame; IsPlaying is one frame old. Setting Volume, Pitch or Loop
costs one component_get and one component_set (no asset bind once the clip is bound); to edit many sources,
write the spans of a ComponentQuery over AudioSourceData.
Exists on AudioSource, Rigidbody and CharacterController is false whenever the component type does not
resolve: in a build or world without the subsystem's components, and also for a mirror that drifted from its
native layout. Entity.HasComponent<T>() and Data still throw InvalidOperationException in both cases, and
drift also logs a native ERROR, so drift stays loud.
Input reads the frame's snapshot: IsKeyDown (held), IsKeyPressed (this frame), IsKeyReleased,
MousePosition, MouseDelta, ScrollDelta, IsMouseButtonDown, the gamepad buttons and axes; the bindings
half adds CursorMode, GamepadName(index), Clipboard and Input.Inject.* (keys, buttons, mouse moves and
gamepad events a script or a test feeds into the next frame).
Rendering settings¶
Rendering holds the renderer's run-time settings, one value for every view, which a game's options menu sets above
the project's and the scene's. Today that is the anti-aliasing:
using Conjure;
public sealed class QualityOptions : ScriptBehaviour
{
// The options menu's "High": 4x MSAA where the GPU has it, 2x otherwise, and FXAA.
public void ApplyHigh()
{
int counts = Rendering.SupportedMsaaSampleCounts; // bit value = sample count: 4 means 4x
Rendering.AntiAliasing = new AntiAliasingSettings
{
MsaaSampleCount = (counts & 4) != 0 ? 4u : 2u,
Post = PostAntiAliasing.Fxaa,
FxaaSubpixel = 0.75f,
};
}
}
Rendering.AntiAliasingreads the value in effect. Until a script sets it, that is the resolved anti-aliasing group of the last rendered frame: the project'srendering.defaults.anti_aliasing, or the winningRenderSettingsDatathat overrides the group. Setting it applies from the next frame and overrides both layers until it is set again; loading a scene keeps it, and nothing saves it, so a game keeps its own options and sets them at start-up. In the editor, stopping play ends it. While a script has set it, the anti-aliasing groupRenderSettings.Resolvereports is the scene's, not the one in effect.AntiAliasingSettingshasMsaaSampleCount(1 is off, then 2, 4 or 8),Post(PostAntiAliasing.NoneorFxaa) andFxaaSubpixel(0 filters edges only, 1 is the softest). A sample count the GPU lacks renders with the largest one it has below it; the value you read back is the one you set.- Setting a sample count other than 1, 2, 4 or 8, a
Postoutside the enum or anFxaaSubpixelthat is not a number in [0, 1] throwsArgumentOutOfRangeExceptionwith the engine's message naming the field, and changes nothing. Rendering.SupportedMsaaSampleCountsis a mask of the counts the GPU supports, whose bit value is the count:1 | 2 | 4 | 8when all are. Bit 1 is always set.- Without a renderer (rendering disabled)
AntiAliasingreadsAntiAliasingSettings.Default(1 sample, no filter, 0.75), setting it changes nothing, andSupportedMsaaSampleCountsis 1.
Warning
Rendering is main-thread only, like the rest of the API. Called from elsewhere, each member asserts in Debug and
Development builds and logs an error; AntiAliasing then throws InvalidOperationException and
SupportedMsaaSampleCounts answers 1.
Assets, scenes and prefabs¶
AssetRef<T> is a uuid plus a lazily bound slot: Load(priority), LoadBlocking(), Release(), IsValid,
IsLoaded, State, AssetRef<T>.Find(path); T is one of the asset tags (PrefabAsset, SceneAsset,
AudioClipAsset, TextureAsset, MeshAsset, MaterialAsset, ModelAsset, EnvironmentAsset,
CollisionMeshAsset). A public AssetRef<T> field is serialised as the uuid and bound when the
scene loads. IsLoaded, State and Version answer false, Unloaded and 0 for a null id or an asset no source
knows, but throw ConjureNativeException (AssetTypeMismatch) when the id names an asset of another type than
T and NotSupportedException when no asset manager runs. Path is "" for an unknown id and throws
NotSupportedException in a cooked or exported game, which has no path table: use it for tooling and logs, not
for gameplay that must run in a shipped build.
Prefab wraps AssetRef<PrefabAsset>: Instantiate(parent, local), InstantiateMany(count, roots,
parent), Prefab.SourceOf(entity), IsInstanceRoot. The static Scene class loads and unloads scene assets by
path or reference (Load(path, additive), Unload, IsLoaded, IsLoadPending, ActivePath, LoadedCount,
LoadedPath(index), EntityCount, StructureVersion, GetRoots); loads complete at the next FRAME_BEGIN.
ActivePath follows Unity's meaning: the first loaded scene, which is the scene of the last non-additive load
(a non-additive load unloads everything before it) or the oldest one when every load was additive. Additive loads
never change it, and when it is unloaded the oldest remaining scene takes over. EntityCount counts the whole
world all loaded scenes share.
Diagnostics and modules¶
Diagnostics.Check(name, passed, detail) records a verdict in the engine's check registry (📘 API: Export and
diagnostics); the test harness and the feature-test scene read them back.
Diagnostics.Stats is the last frame's FrameStats (FrameMs, SubmitMs, FixedSteps, JobsExecuted,
FrameMemoryHighWater, PhaseMs(EnginePhase) or PhaseMs(index) with the index 0..9 of an EnginePhase, in
execution order FrameBegin to FrameEnd); Diagnostics.LastError(out status) reads the native last-error text.
Modules.Registry lists every discovered module as ModuleInfo { Name, Version, State, Kind, FeatureFlags,
IsLoaded }; it is read-only, loading is the editor's and the project's business.
Note
Diagnostics.Draw.Line, Box and Sphere validate their arguments and are counted, but draw nothing in an
application yet: the engine does not publish its renderer::debug_draw to the bindings
((e)). A hand-built binding_context with debugDraw set does
draw. Diagnostics.Draw.Text draws nothing in any configuration (no world-space text renderer in v1).
Data-oriented scopes¶
ComponentQuery.Begin<T1, T2>() locks the world and walks every chunk that holds the requested components:
NextChunk(out ChunkView chunk), then chunk.Get<T1>(0), chunk.Get<T2>(1) as Span<T> and
chunk.Entities. Writes through the spans are writes into the engine's memory, no copies. Get<T>(column)
throws InvalidOperationException when T is not the component requested at that position of Begin, so a wrong
type or index never reinterprets another component's memory. The scope ends with Dispose() (a using block),
which also flushes every structural request made meanwhile. The compiler keeps the query, its chunks and their
spans on the stack (no class field, box or capture), not inside the scope: a span taken before Dispose() or a
copy of the query must not be used after it. Doing so is undefined; outside Distribution the engine overwrites the
chunk views when the scope ends, which catches some of these mistakes, never all. Begin is available inside
OnFixedUpdate, OnUpdate, OnLateUpdate, the collision callbacks and the OnCreate / OnDestroy the end of
those phases runs; elsewhere (an OnCreate at scene start, frame end or a mode change) it throws
InvalidOperationException naming NOT_IN_PHASE.
using (ComponentQuery query = ComponentQuery.Begin<LocalTransform, RigidBodyData>())
{
while (query.NextChunk(out ChunkView chunk))
{
Span<LocalTransform> transforms = chunk.Get<LocalTransform>(0);
for (int i = 0; i < chunk.Count; ++i)
{
transforms[i].Position.Y = MathF.Max(transforms[i].Position.Y, 0.0f);
}
}
}
Warning
Inside a scope Entity.Create, Destroy, AddComponent, RemoveComponent, SetParent, Enabled and
Prefab.Instantiate are deferred to the end of the scope (the handles they return are valid at once); a
Duplicate() cannot be deferred and throws InvalidOperationException (STRUCTURE_LOCKED). Deferred requests
apply in call order and the getters keep answering the old state until then: Enabled = false then
Enabled = true ends enabled, while Enabled reads its old value inside the scope. SetParent to the entity
itself throws ArgumentException at once; a reparent the scene refuses when it is applied (a cycle, the depth
limit) already returned and is logged as a warning.
Hot reload¶
Rebuild the game assembly (script.compile in the editor, or dotnet build) and the engine reloads it: it
collects every serialised field, destroys the instances, unloads the old assembly, loads the new one and recreates
the instances with the saved fields (OnCreate runs again, OnStart does not). A class that vanished keeps its
field JSON and is disabled with one warning; it comes back when a later build restores it. Private state resets to
its initialisers. Plugin assemblies share the game load context, so a leaky plugin assembly prevents unloading.
Functions¶
| Member (short) | Purpose |
|---|---|
ScriptBehaviour: OnCreate, OnStart, OnFixedUpdate(float), OnUpdate(float), OnLateUpdate(float), OnDestroy, OnCollisionEnter/Exit(in Collision), OnTriggerEnter/Exit(Entity) |
the callbacks |
Entity: Create, Find, FindByGuid, FindByTag, FindByLayer, CreateMany, IsAlive, Name, Destroy, AddScript<T>, GetScript<T>, component accessors, Parent, Root, Enabled, Tag, Layer, Guid, Duplicate |
entities |
Transform: Position, Rotation, Scale, Local, World, WorldMatrix, Forward/Right/Up, SetParent, GetChildren, Translate, Rotate, LookAt, Interpolated; TransformData |
transforms |
Rigidbody, ForceMode, CharacterController, Physics, LayerMask, RaycastHit |
physics |
AudioSource, Audio |
audio |
Input (+ Input.Inject, ButtonAction), Key, MouseButton, GamepadButton, GamepadAxis, CursorMode |
input |
AssetRef<T>, AssetId, AssetState, AssetLoadPriority, the asset tags, Prefab, Scene |
assets, scenes, prefabs |
Diagnostics, FrameStats, EnginePhase, Modules.Registry, ModuleInfo, Log, Time |
diagnostics and services |
ComponentQuery, ChunkView, ComponentType<T> |
the DOD escape hatch |
See also: