Games in Tallow are written in C# 15 on .NET 11. The engine and the editor are native code; your scripts are
compiled into a game assembly that the editor loads for Play and that release builds compile to native code.
Your first script
Create a script in the Project window (right-click > Create > C# Script) or write a .cs file anywhere in the
project’s src folder. A component is a class deriving from Script and marked [Component]:
using System.Numerics;
using Tallow;
namespace MyGame;
[Component]
public class Spinner : Script
{
public Vector3 DegreesPerSecond = new(0, 45, 0);
public override void Update(TickInput input, float deltaTime)
{
Transform.Rotate(DegreesPerSecond * deltaTime);
}
}Save the file and the editor compiles it in the background. Select an object and use Add Component > Scripts
(or drag the .cs file onto the object), then press Play. Compiler errors appear in the Console and block Play
until they are fixed; the editor itself stays usable. Saving a script during Play reloads it in the running game,
and its fields keep their values. System.Numerics is imported in every C# project.
Changing a Vector3 property such as Transform.Position changes a copy: assign the result back
(Transform.Position += Vector3.UnitX * deltaTime;).
Fields in the Inspector
Public fields of supported types appear in the Inspector and are saved with the scene or prefab, and applied
before Awake. Private fields are shown and saved with [ShowInInspector], saved but hidden with
[HideInInspector], and [NonSerialized] leaves any field out. A numeric [Range] draws a slider.
[SerializedFieldId] is an optional hint that keeps a value when a field is renamed.
Callbacks
Awake,Start,OnEnable,OnDisable,Update(TickInput input, float deltaTime),
LateUpdate(TickInput input, float deltaTime),FixedUpdate(float deltaTime)andOnDestroy. Gameplay reads input from theTickInputit is given, so the same code runs in single
player and in a network session.OnValidate()runs when a field changes in the Inspector during Play;OnDrawGizmos(bool selected)draws with
Gizmos.Line/Sphere/Box(DebugDrawdraws in the game too).- Physics:
OnCollisionEnter/Stay/Exit(Collision)andOnTriggerEnter/Stay/Exit(GameObject)for colliders with
isTrigger;OnControllerHit(ControllerHit)for what a character controller ran into. Enter and Exit run once
per pair after the tick’s physics step on every machine that simulates the tick, never during prediction
replays; checkScene.IsServerbefore changing authoritative state. OnNetworkEvent(name, value)withSendNetworkEvent(name, value), and the save hooksOnSaving()and
OnLoaded().- An exception in a script is logged once in the Console with the file and line it came from (repeats count
up); click it to open the script there. The script keeps running.
Waiting and async code
await works on the game thread: await NextFrame();, await Wait(2f); (game time) and
await Task.Delay(ms, Destroyed). Code after an await runs once a frame after LateUpdate and may use the engine.
Waits end when the script is destroyed; pass Destroyed to other async calls. Avoid ConfigureAwait(false): the
engine must not be used off the game thread.
Multiplayer
[Sync]on a field (public or private; numbers, bool, string, enums, vectors) shares the server’s value with
every client in the session when it changes, and with players who join later. Change it on the server; a
client’s own changes are overwritten.[Rpc]methods run across the network:[Rpc(RpcTarget.Server)]on the server only,[Rpc](Everyone) on
the server and every client. Call them withRpc(nameof(Fire), aim, power). The server may call any; a client
only on an object it owns. Parameters: int, float, bool, string, enums, Vector2/3/4 and GameObject. Inside one,
RpcSenderis the caller’s client id.
See the networking guide for sessions, prediction and spawning.
Saving
[Saved] fields are kept in save games: SaveGame.Save("slot") and SaveGame.Load("slot"). The saving guide
covers custom storage.
Assemblies and NuGet packages
A *.tasmdef file splits a project’s scripts into assemblies:
{"name":"Gameplay","rootNamespace":"MyGame.Gameplay","references":["Core"]}. rootNamespace is optional (the
name by default) and is used for new scripts in that folder; nested definitions own their own folders. Click one
in the Project window to edit it in the Inspector.
NuGet packages are listed in a folder’s .tasmdef, one exact version each:
"packages": [{ "id": "Newtonsoft.Json", "version": "13.0.4" }]. Scripts in that folder (and the main game
assembly) can use them, and built games ship them with THIRD-PARTY-NOTICES.txt. Tallow does not check package
code, so use packages you trust.
Renaming scripts
The editor follows a class renamed inside its file by the file’s .tmeta ID. When moving a class to another file
or namespace, add [FormerlyNamed("OldNamespace.OldName")] so scenes, prefabs and built games still find it.
Trusted code only
Game assemblies are your own trusted code. .tasmdef boundaries organise source; they are not a security
boundary, and Tallow has no sandbox for untrusted .NET code, so it does not load third-party mods.
Running from the command line
TallowLauncher --open /path/to/MyGame # open the project in the editor
TallowLauncher --build-project /path/to/MyGame # compile its C# only
TallowLauncher --game --project /path/to/MyGame # run the compiled game without the editorIf .NET cannot be found, check the Console and dotnet --list-runtimes. Tallow looks in DOTNET_ROOT, the
installed dotnet, and the standard install folders (including /usr/lib64/dotnet on Fedora).
Inspector field types
The Inspector edits fields of these types: float, double, int, uint, long, bool, single-line
string, enums, Vector2, Vector3, Vector4 and Color; arrays and lists of those; [Serializable] structs
and classes of your own (shown as foldouts, up to four levels deep) and lists of them; and references to objects
and components (below). [ShowInInspector], [HideInInspector] and [NonSerialized] work the same for every type.
Strings can hold spaces and any Unicode text, but not tabs, line breaks or NUL characters.
Object reference fields
A public field of type GameObject, Transform, a built-in component
(Light, Rigidbody, MeshRenderer, Animator, NavigationAgent, …)
or another C# script shows an object slot in the Inspector. Drag an object
from the Hierarchy onto it, or press … to pick from the objects that
fit (for a Light field, the objects with a Light; for a script field, the
objects with that script). Nullable fields (GameObject?, Door?) work the
same way.
public class DoorSwitch : Script
{
public GameObject Door;
public Light Lamp;
public DoorSwitch? Next;
}References are saved as a list of objects on the component, so they keep
pointing at the right object when a scene loads, and inside a prefab each
copy points at its own objects. Before a script’s Awake runs, its
references are set; a referenced C# script whose object comes later in the
scene is brought up first, so its own Awake has run too. A reference to an
object that was deleted is null (or the empty handle, whose IsValid is
false, for a built-in component field). Graph object variables are fields of
these types, so they are set the same way.
When a field cannot be restored, the script’s Awake does not run; when editing during Play, a field change that
fails leaves the previous saved value in place.
ECS data and queries
A [Component] struct is ECS data: it lives in the engine’s Flecs world,
packed with every other entity’s, instead of in a script per object. Its
fields can be bool, int, uint, long, ulong, float, double,
Vector2/3/4 or Quaternion.
[Component]
public struct Mover
{
public Vector3 Velocity;
public float Drag;
}
public class Movers : Script
{
public override void Start()
{
// On a GameObject's entity, or on a bare entity with no GameObject at all.
GameObject.Entity.Set(new Mover { Velocity = Vector3.UnitX, Drag = 0.1f });
Scene.CreateLocalEcsEntity().Set(new Mover { Velocity = Vector3.UnitZ });
}
public override void Update(TickInput input, float deltaTime)
{
Scene.Query<Mover>().ForEach((EcsEntity entity, ref Mover mover) =>
mover.Velocity *= 1f - mover.Drag * deltaTime);
}
}EcsEntity.Set,Get,TryGet,HasandRemovework on one entity;
GameObject.Entityis an object’s entity andEcsEntity.GameObjectthe
other way (null for a bare entity).Scene.Query<A>(),Query<A, B>()andQuery<A, B, C>()give the
entities with all of them:Count, andForEachwith arefto each. The
data is copied out in pages and the rows the action changed are written back
after it, so it costs a few calls per thousand entities, not one per entity.- In
ForEachyou may create and destroy entities and add or remove data. An
entity that has gone (or lost one of the components) by the end is not
written back, and entities made during it are visited next time. - ECS data is not saved with the scene. In a network session, a
[Component]
struct’s[Sync]fields are replicated like a Beef one’s: entities the server
makes arrive on clients and changes follow (docs/networking.md). Bare entities
are deleted when Play stops. - Visual script graphs get the same nodes for each struct: Has, Add and Remove
Component, Get and Set of each field, and For Each, which visits the
active GameObjects that have it.
Code that runs when the game starts: [GameStart]
A static method with no parameters marked [GameStart] runs once when the game’s code loads: before the first
scene starts and before any script’s Awake (and again after a hot reload, with the new code). It is the place
for game-wide settings, such as where saves go (docs/saving.md):
static class Setup
{
[GameStart]
internal static void Begin() => SaveGame.Storage = new ServerStorage();
}It may be in any class, public or internal, in any of the game’s assemblies. A method that throws is reported in
the Console with its stack, and the others still run. The build refuses a [GameStart] method that is not static,
takes parameters, returns a value, or is private.
Spawning networked objects
A prefab whose root has a Network Identity is shared. On the server, Scene.Spawn makes it on every machine and
can hand it to a player; Scene.Despawn removes it everywhere. Give prefab files short names once at startup,
with the same names on the server and the clients.
public override void Start() => Network.RegisterPrefab("crate", "Prefabs/Crate.tprefab");
void DropCrateFor(GameObject player)
{
if (Scene.IsServer)
Scene.Spawn("crate", player.Transform.Position + new Vector3(0, 2, 0), player.OwnerClientId);
}A despawned object reads as gone straight away (IsValid is false); its scripts’ OnDestroy runs at the end
of the frame.
UI documents with C# code-behind
Put a UI Document and a C# script on the same object. The document’s onclick="Method", onchange and
onload call that script’s method of the name (it can take nothing, a UIElement, or the element’s id as a
string), and bind="field" shows and edits the script’s public field. From code, GetComponent<UIDocument>()
gives the document; Find("id") an element, with Text, Visible and Value.
public class MainMenu : Script
{
public string playerName = "Player";
void OnPlay(UIElement button) =>
GetComponent<UIDocument>().Find("status")?.SetText($"Have fun, {playerName}!");
}Visual scripting graphs in C# projects
A .tgraph in a C# project compiles to C#: Compile in the graph editor writes Name.cs beside the graph, a
public partial class Name : Script in the namespace a new C# script in that folder would get. Drop the graph on
an object to add it (its compiled script is what runs); the generated file is hidden in the Project panel and
travels with the graph in packages. Do not edit it: compile the graph again instead, or use Convert to Script to
keep the code and drop the graph. Because the class is partial, a hand-written partial class Name in another
file can add methods the graph’s nodes cannot express.
The node list in a C# project leaves out nodes that only exist for Beef (the engine’s Beef API, Beef
[GraphNode] methods, ECS For Each Data). In their place, every public property, field and method of
Tallow.API’s gameplay types and of your own public C# types becomes a node (under Engine and My Scripts), as
long as a pin can carry its parameters and result: numbers, bools, text, vectors, rotations, colours, enums,
GameObject, Transform, the physics handles and your scripts. The build writes the list
(.tallow-csharp/graph-nodes.tsv) even when the game does not compile, so a graph can be finished first. Object variables of GameObject and physics handle types are handles
(never null): Is Valid asks whether the object still exists.
To compile a graph without the editor (tests, build scripts):
TallowLauncher --graph-compile path/Name.tgraph GameNamespace.
Editor scripts: custom Inspectors, windows, menu commands and Preferences
C# in any folder named Editor under src/ is an editor script, as in Unity. Tallow.Build compiles those files
into an assembly of their own, Tallow.Game.Editor, which sees the game’s assemblies and Tallow.Editor
(Managed/Tallow.Editor). Nothing in the game references it, so a game build never contains it or Tallow.Editor.
Game code that uses Tallow.Editor does not compile, and the code editor marks it. Project > Create > C# Script >
Editor makes each kind below with the boilerplate written, and puts the file in an Editor folder (made when the
folder shown is not in one).
The editor loads the editor scripts after every successful compile, apart from a running game, so they work in Edit
mode and during Play. A recompile replaces them. Windows that were open stay open, and the windows open when the
editor closed open again next time. An exception in an editor script is reported once in the Console. The editor
carries on, and a failed Inspector falls back to the plain field list.
- Custom Inspector:
[CustomInspector(typeof(Door))] class DoorInspector : Inspectoroverrides
OnInspectorGUI()and draws Door’s section, and also the section of scripts deriving from Door that have none of
their own.DrawDefaultInspector()draws every field as the Inspector would, andField("openAngle")draws one.
Target.GetFloat/SetFloat("openAngle", ...)(andGet/Setas text, bool, int, Vector3, enum) read and change
the saved values. Changes go through undo, are saved with the scene, callOnValidate, and reach the running
script during Play. - Inspector for a built-in component: the same attribute on a
ComponentInspectornames the component’s handle
type instead of a script:[CustomInspector(typeof(Light))] class LightInspector : ComponentInspectordraws the
Light section of every object with one, in place of the plain field list.Targetis anEditorComponent:
Get/Setas text (the scene file’s own form),GetFloat/SetFloat,GetInt,GetBool,GetString,
GetEnum,GetVector3and their setters, plusTarget.Fields(name and kind).Field("intensity")draws one
field with the editor’s widget,DrawDefaultInspector()draws them all. Built-in handles (Light, MeshRenderer,
colliders, …) and class components alike; changes call the component’s OnValidate and go through undo. - Editor window:
[EditorWindow("Level/Statistics")] class Stats : EditorWindowappears in the Tools menu
under Level > Statistics, and itsOnGUI()draws it. It docks like any other window, andClose()closes it. - Menu command:
[MenuItem("Level/Rename Lights")] static void Rename()runs when chosen from Tools. - Scene editing:
EditorSceneworks on the open scene, so a menu command or an Inspector can do to objects what
the editor’s own tools do.EditorScene.Selectionreads and sets what is selected;Find("Level/Walls/Wall 1")
finds by path or by name;Rootslists the scene’s objects;Create("Cube")makes one of the editor’s built-in
objects ("Cube","Point Light","Create Empty", …), where the editor puts it or under a parent; and an
EditorObjecthasName,Parent,Children,Position,Rotation(Euler degrees),Scale,Components,
Duplicate(),Delete()andSelect().AddComponent("Tallow.Light"),Component("Tallow.Light")and
RemoveComponent(...)work for built-in components and class components alike, and their fields read and write
as scene files do. Every change marks the scene dirty and can be undone; during Play they are refused
(EditorScene.IsEditable). - Models:
EditorModel.Read(object)gives the object’s Model Mesh as anEditMesh(Dispose it when done), and
EditorModel.Write(object, mesh)makes a mesh the object’s Model Mesh, adding a Mesh Renderer when it has none.
The whole modelling API works on it (docs/modeling.md): the modeller’s shapes,ExtrudeFaces,InsetFaces,
Subdivide,Poke,Solidify, face colours, materials and smoothness,Combinebooleans, UVs,ToTextand
FromText. Writing marks the scene dirty, so it is undone with the rest of the command. Editor scripts can also
use Tallow.API’s scene-free calls, such asGizmosandDebugDraw. - Terrain:
EditorTerrain.Begin(object)opens a terrain undo record for the object with the terrain; the
script digs and raises it with Tallow.API’sVoxelTerrain.ModifySphere(or the other brush calls), and ending
the record makes those changes one undo step, as a brush stroke is:
using (EditorTerrain.Begin(ground)) terrain?.ModifySphere(point, 3, -5);Chunks that were not loaded
when the record started are made again on undo, as with the editor’s own sculpting. - Scene view overlay: any concrete
SceneViewOverlaysubclass is called every frame while the Scene view is
open (OnSceneViewGUI()), to draw gizmos and run a tool.SceneView.Line/Sphere/Boxdraw this frame (the same
batches asTallow.Gizmos:onTopdraws through geometry);SceneView.IsVisible,IsMouseOver,IsClicked,
IsMouseDown,MousePoint,Ray(point),Pick(point)andPickUnderMouse()give the mouse and what it is
over. It runs while the editor renders, so draw gizmos rather than widgets: an editor window is for those. - Preferences tab:
[PreferencesPage("Level Tools")]on a plain settings class (public fields with defaults)
gives it a tab in Edit > Preferences. The tab shows the fields and saves every change. Read the settings anywhere
withEditorPrefs.Get<LevelToolSettings>(). On a class deriving fromPreferencesPage, the attribute adds a tab
that the class draws itself withOnGUI(). - Settings:
EditorPrefsholds this user’s settings for every project on this machine, in
editor-prefs.jsonin the editor’s config folder.ProjectPrefsholds the project’s settings for everybody
working on it, inProjectSettings/EditorPrefs.json. Both offerGet<T>()/Save(settings)for settings
objects (public fields, as JSON) andGetFloat/SetFloat,GetInt,GetBool,GetStringby key. A change is
written at once.
Widgets are EditorGUI calls, drawn top to bottom each frame. Each returns its value, the new one when it was
edited:
- text:
Label,Heading,HelpBox; - buttons and fields:
Button,Toggle,FloatField,Slider,IntField,Vector3Field,ColorField,
TextField,Popup,EnumPopup,Fields(object); - layout:
Foldout,ProgressBar,Tooltip,Separator,SameLine, andusingscopesDisabled(),
Indented(),Id(n).
Labels sit on the left as in the Inspector. Two widgets with the same label in one window need a ## suffix
("Speed##front") or an Id scope. EditorApplication gives IsPlaying, ProjectPath, SelectedObjectName and
Log/LogWarning/LogError to the Console.
Shipping a C# game
File > Build (or dotnet run --project <engine>/Managed/Tallow.Build -- export <project> --output <folder>) builds a C#
project into a folder that runs on its own: the engine’s precompiled player renamed to the
game, game.tpak, Managed/ (Tallow’s runtime and the game’s Release assemblies) and
dotnet/, a copy of the .NET runtime, so players need not install .NET. Pass
--no-bundle-dotnet (or untick Include .NET in File > Build, saved as bundleDotNet = 0 in project.tallow) for a
smaller build that needs .NET installed. Editor scripts are never in a game build.
Spotted a mistake? Open an issue.