Command

The Command system provides an attribute-based command registration and execution framework. Methods decorated with [Command] are automatically discovered and can be invoked by name with string-based parameter parsing — ideal for developer consoles, debug tools, and chat commands.

Architecture

spinner

Data Flow

spinner

Key Concepts

Concept
Description

Attribute-based discovery

Methods decorated with [Command] are auto-discovered at editor load via reflection

Fuzzy search

Command.Search() uses subsequence matching to find commands by partial name

String parameter parsing

All parameters are passed as strings and converted via CommandParameterParser

Runtime vs Editor

[RuntimeCommand] restricts execution to play mode; [EditorCommand] is editor-only

Quick Start

Defining a Command

public static class MyCommands
{
    [Command("set-health")]
    public static void SetHealth(int amount)
    {
        Player.Health = amount;
    }

    [RuntimeCommand("spawn-enemy")]
    public static void SpawnEnemy(string enemyType, int count)
    {
        // Only available during play mode
        EnemyManager.Spawn(enemyType, count);
    }
}

Executing a Command

Registering a Custom Parser

Files

File
Description

Static entry point for command lookup, execution, and search

Attributes for marking methods as commands

Wraps a MethodInfo with name matching and parameter extraction

Wraps a ParameterInfo with string-to-value parsing

Sealed type-based parser registry for string-to-object conversion

See Also

  • CommandProvider — Internal static class that discovers and caches commands via reflection

  • CommandSearch — Internal static class that performs fuzzy scoring against registered commands

  • CommandSearchResult — Record containing the matched CommandMethod and its fuzzy score

Last updated