|
| 1 | +# Debug Commands |
| 2 | + |
| 3 | +`DebugCommand` is an attribute that can be placed on classes, fields, methods, and properties to expose them to Debug Commands interface which can be used for configuration, modding, or tooling. |
| 4 | + |
| 5 | +> [!TIP] |
| 6 | +> Only `static` members can be used in debug commands. |
| 7 | +
|
| 8 | +## Access |
| 9 | + |
| 10 | +### Output Log |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +[Output Log](../../editor/windows/output-log.md) is Editor window that displays the full log. At the bottom of that window, there is an input command field that can be used to run commands. You can type commands with an automatic search popup that displays similar commands based on the entered value. Use arrow keys to navigate around that popup list. The tab key can be used to autocomplete commands based on the best-found match. Finally, when input is empty you can use the arrow up key to navigate around the command history and re-try one of them again. |
| 15 | + |
| 16 | +### In-game console |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +Debug Commands can appear within an in-game console or debug tooling. For example, [Arizona Framework](https://github.com/FlaxEngine/ArizonaFramework) implements console via [ImGui](https://github.com/FlaxEngine/ImGui). Such tool can be useful when developing games for various platforms and devices such as consoles where game configurations can be tweaked at runtime. |
| 21 | + |
| 22 | +### `DebugCommands` API |
| 23 | + |
| 24 | +Use `DebugCommands` class to execute or list debug commands within the project. It caches all commands for engine, game, and plugin projects. |
| 25 | + |
| 26 | +Example usage: |
| 27 | + |
| 28 | +# [C#](#tab/code-csharp) |
| 29 | +```cs |
| 30 | +// Disable vsync |
| 31 | +DebugCommands.Execute("Graphics.UseVSync false"); |
| 32 | +``` |
| 33 | +# [C++](#tab/code-cpp) |
| 34 | +```cpp |
| 35 | +// Disable vsync |
| 36 | +DebugCommands::Execute(TEXT("Graphics.UseVSync false")); |
| 37 | +``` |
| 38 | +*** |
| 39 | +
|
| 40 | +## Example |
| 41 | +
|
| 42 | +# [C#](#tab/code-csharp) |
| 43 | +```cs |
| 44 | +using FlaxEngine; |
| 45 | +
|
| 46 | +/// <summary> |
| 47 | +/// Global gameplay configs. |
| 48 | +/// </summary> |
| 49 | +[DebugCommand] |
| 50 | +public static class GameGlobals |
| 51 | +{ |
| 52 | + /// <summary> |
| 53 | + /// Disables player damage. |
| 54 | + /// </summary> |
| 55 | + public static bool GodMode = false; |
| 56 | +} |
| 57 | +
|
| 58 | +/// <summary> |
| 59 | +/// Player script. |
| 60 | +/// </summary> |
| 61 | +public class PlayerLogic : Script |
| 62 | +{ |
| 63 | + /// <summary> |
| 64 | + /// Player speed scale. |
| 65 | + /// </summary> |
| 66 | + [DebugCommand] |
| 67 | + public static float SpeedScale = 1.0f; |
| 68 | +
|
| 69 | + /// <summary> |
| 70 | + /// Restores player HP to max. |
| 71 | + /// </summary> |
| 72 | + [DebugCommand] |
| 73 | + public static void HealPlayer() |
| 74 | + { |
| 75 | + //.. |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | +# [C++](#tab/code-cpp) |
| 80 | +```cpp |
| 81 | +// Global gameplay configs. |
| 82 | +API_CLASS(Static, Attributes="DebugCommand") class GAME_API GameGlobals |
| 83 | +{ |
| 84 | + DECLARE_SCRIPTING_TYPE_NO_SPAWN(GameGlobals); |
| 85 | +public: |
| 86 | + // Disables player damage. |
| 87 | + API_FIELD() static bool GodMode; |
| 88 | +}; |
| 89 | + |
| 90 | +// Player script. |
| 91 | +API_CLASS() class GAME_API PlayerLogic : public Script |
| 92 | +{ |
| 93 | + API_AUTO_SERIALIZATION(); |
| 94 | + DECLARE_SCRIPTING_TYPE(PlayerLogic); |
| 95 | +public: |
| 96 | + // Player speed scale. |
| 97 | + API_FIELD(Attributes="DebugCommand") static float SpeedScale; |
| 98 | + |
| 99 | + // Restores player HP to max. |
| 100 | + API_FUNCTION(Attributes="DebugCommand") static void HealPlayer(); |
| 101 | +}; |
| 102 | +``` |
| 103 | +*** |
0 commit comments