Skip to content

In‐Game Debugging

Valk edited this page Sep 6, 2025 · 21 revisions

Index

Visualize

If the videos do not load please try refreshing the page.

2024-09-10.13-40-24.mp4
2024-09-08.21-37-51.mp4

Easily debug in-game by adding the [Visualize] attribute to any of the supported members. This feature allows you to visualize and interact with various types of data directly within the game environment.

Supported Members

Member Type Supported Example Types Additional Notes
Numericals int, float, double All numerical types are supported
Enums Direction, Colors All enum types are supported
Booleans bool
Strings string
Color Color
Vectors Vector2, Vector2I, Vector3, Vector3I, Vector4, Vector4I
Quaternion Quaternion
NodePath NodePath
StringName StringName
Methods Method parameters support all listed types here
Static Members This includes static methods, fields, and properties
Arrays int[], string[], Vector2[] Arrays support all listed types here
Lists List<string[]>, List<Vector2> Lists support all listed types here
Dictionaries Dictionary<List<Color[]>, Vector2> Dictionaries support all listed types here
Structs struct
Classes class
Resources Resource
Godot Classes PointLight2D, CharacterBody3D
Godot Array Godot.Collections.Array Tracking in https://github.com/ValksGodotTools/Template/issues/58
Godot Dictionary Godot.Collections.Dictionary Tracking in https://github.com/ValksGodotTools/Template/issues/58

Important

There are some annoyances when trying to visualize members from inherited classes. I will try to solve this later.

Example Usage

public partial class Player : CharacterBody2D
{
    // You will be able to edit this in-game
    [Visualize] private static int _totalPlayers;

    private State _currentState;

    public override void _Ready()
    {
        // Visualize.Register(this) is required for the tool to even see this script, every other parameter is optional
        // currentState and Rotation will be observed as readonly members.
        Visualize.Register(this, nameof(_currentState), nameof(Rotation));
        _currentState = new State("Idle");
    }

    // You will be able to execute this method in-game
    [Visualize]
    public void Attack(int damage)
    {
        Visualize.Log(damage); // Floating text will appear near node then disappear
    }
}

Console Commands

Note

The in-game console can be brought up with F12

Registering new commands is easy.

public override void _Ready()
{
    GameConsole.RegisterCommand("help",  CommandHelp);
    GameConsole.RegisterCommand("quit",  CommandQuit).WithAliases("exit");
    GameConsole.RegisterCommand("debug", CommandDebug);
}

private void CommandHelp(string[] args)
{
    IEnumerable<string> cmds = GameConsole.Instance.GetCommands().Select(x => x.Name);
    Logger.Log(cmds.ToFormattedString());
}

private async void CommandQuit(string[] args)
{
    await Global.Instance.QuitAndCleanup();
}

private void CommandDebug(string[] args)
{
    if (args.Length <= 0)
    {
        Logger.Log("Specify at least one argument");
        return;
    }

    Logger.Log(args[0]);
}

Custom Main Run Args

In Godot top left Debug > Customize Run Instances... > Main Run Args there are custom defined arguments you can use.

Window Position and Size Args

  • top_left
  • top_right
  • bottom_left
  • bottom_right
  • middle_left
  • middle_right
  • middle_top
  • middle_bottom

These args are great when running multiple client windows when debugging multiplayer. For example Client A window could be "middle_left" and Client B window could be "middle_right".

Watching Variables

// Metrics Overlay can be toggled in-game with F1
// You can also do MetricsOverlay.StartMonitoringPhysicsProcess and MetricsOverlay.StopMonitoringPhysicsProcess
MetricsOverlay.StartMonitoringProcess("My Variable", () => _variable);
//MetricsOverlay.StopMonitoringProcess("My Variable");

Profiling

// _Ready
Profiler.Start("Player Initialization");
PlayerSetup();
Profiler.Stop("Player Initialization"); // This will be printed to the console

// _Process
// You can also do Profiler.StartPhysicsProcess and Profiler.StopPhysicsProcess
Profiler.StartProcess("Player Firing Logic");
PlayerFire();
Profiler.StopProcess("Player Firing Logic"); // This will be displayed in the MetricsOverlay (F1)
Clone this wiki locally