CVars & Console Commands
The Console
Chisel has a built-in developer console you can open at runtime by pressing the tilde key (~). By default, opening the console also pauses the game. You can separate these by setting MainEngine.PauseWhenMenusOpen = false in your game setup, which lets the console be a pure overlay without affecting game state.
Built-in commands worth knowing:
listcmd Prints all registered commands to the console log.
map [name] Loads a map by name from the Maps folder, or by full path. Use map unload to unload the current map.
timescale [value] Sets the game’s time scale. Useful for slow-motion debugging. 1.0 is normal speed.
fov [value] Sets the world camera field of view.
z_near / z_far [value] Sets the near and far clip planes for the camera.
ent fire [name] [action] Manipulates a named entity. Supports remove, set pos/rot/scale x,y,z, and read pos/rot/scale.
ent create [classname] [x,y,z] Spawns an entity by class name at a world position.
quit Exits the game.
Write to the console log from code using MainEngine.Instance.Console.AppendLog(message). This is how all built-in commands print their output.
CVars
A CVar is a named value that can be read in code and changed at runtime through the console. They’re the standard way to expose tunable numbers like movement speeds, weapon damage, or rendering settings without recompiling. Declare one as a static field anywhere in your project:
public static CVarFloat maxRunSpeed = new CVarFloat(“pl_runspeed”, 9.0f);
public static CVarInt maxAmmo = new CVarInt(“wep_maxammo”, 30);
public static CVarBool godMode = new CVarBool(“sv_godmode”, false);
The first argument is the console name and the second is the default value. Once declared the CVar is automatically registered and can be changed at any time by typing its name followed by a new value:
pl_runspeed 14
sv_godmode 1
wep_maxammo 999
Typing a CVar name with no arguments prints the current value and the default. The three built-in types are CVarFloat, CVarInt, and CVarBool. All three have implicit conversions to their underlying type, so you use them directly in expressions:
// Both of these work identically
float speed = maxRunSpeed.GetValue();
float speed = maxRunSpeed;
Always declare CVars as static fields. If you declare one inside a constructor or a method, it only gets registered when that code runs, which may be after the console is already in use or may never happen at all.
Custom Console Commands
For commands that execute logic rather than just holding a value, use CommandBinding directly. Also declare these as static fields:
public static readonly CommandBinding cmdKillAll = new CommandBinding(“kill_all”, (string[] args) =>
{
foreach (var entity in EntityManager.entities.GetValues())
{
if (entity.controller is LivingActor actor)
entity.TakeDamage(new DamageInfo { damage = 9999, damageType = -1 });
}
MainEngine.Instance.Console.AppendLog(“Done.”);
});
The callback receives a string[] of everything typed after the command name, split by spaces. If the user types mycommand foo bar 123, args will be [“foo”, “bar”, “123”]. You’re responsible for parsing and validating them. In release builds, exceptions thrown inside a command callback are caught and printed to the console log rather than crashing the game.
Custom CVar Types
If you need a CVar for a type beyond float, int, or bool, use CVarType<T> directly with a custom parse function:
public static CVarType<string> playerSkin = new CVarType<string>(“pl_skin”, “default”, (s) => s);
public static CVarType<Vector3> spawnPoint = new CVarType<Vector3>(“sv_spawnpoint”, Vector3.Zero, (s) =>
{
var parts = s.Split(’,’);
return new Vector3(float.Parse(parts[0]), float.Parse(parts[1]), float.Parse(parts[2]));
});
The third argument is a function that converts the raw console string into your type. The same print-on-no-args behavior applies.