Skip to content

In‐Game Debugging

Valk edited this page May 15, 2025 · 10 revisions

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

// You will be able to view realtime changes to curState, Position and Rotation
[Visualize(nameof(currentState), nameof(Position), nameof(Rotation))]
public partial class Player : CharacterBody2D
{
    // You will be able to edit this in-game
    [Visualize] private static int _totalPlayers;

    // Visualize will check every 1000ms if currentState gets defined
    State currentState;

    public override void _Ready()
    {
        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

Important

Static functions are not yet supported. Should be easy to implement, I have not got around to doing it yet.

Adding the ConsoleCommand attribute to any function will register it as a new console command.

Note

The in-game console can be brought up with F12

[ConsoleCommand("help")]
void Help()
{
    IEnumerable<string> cmds = Game.Console.Commands.Select(x => x.Name);

    Game.Log(cmds.Print());
}

Console commands can have aliases, this command has an alias named "exit"

[ConsoleCommand("quit", "exit")]
void Quit()
{
    GetTree().Root.GetNode<Global>("/root/Global").Quit();
}

Most method parameters are supported, allowing for more dynamic interactions

[ConsoleCommand("debug")]
void Debug(int x, string y)
{
    Game.Log($"Debug {x}, {y}");
}

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".

Exports

If you forget to set an [Export], you will be reminded when you start the game. You can disable this if you do not like it by removing the Exports.cs autoload.

Clone this wiki locally