A lightweight, extensible in-game debug console for Unity that allows developers to expose methods as console commands using simple attributes. Perfect for debugging, testing, and creating developer tools in your Unity projects.
- Attribute-Based Command System - Mark any method with
[Command("CommandName")]to instantly make it accessible from the console - Build Stripping Support - Keep sensitive developer commands out of production builds with the
stripparameter - Type-Safe Parameters - Automatic type conversion for common types (int, float, bool, string, enum, etc.)
- Command History - Navigate previous commands with up/down arrow keys
- Clean UI - Built with TextMeshPro for crisp, scalable text rendering
- Auto-Discovery - Automatically finds and registers commands from MonoBehaviours and static methods
- Static & Instance Methods - Support for both static commands and instance-based commands
- Built-in Help System -
helpcommand lists all available commands with descriptions - Zero Setup - Add prefab to scene and start creating commands immediately
- Open Unity Package Manager (
Window > Package Manager) - Click the
+button in the top-left corner - Select
Add package from git URL... - Enter:
https://github.com/16Byte/PixelPerfectConsole.git
- Download or clone this repository
- Copy the root folder into your project's
Assetsdirectory
Drag the ConsoleUI prefab from Samples/Prefabs/ConsoleUI.prefab into your scene. That's it! The console is ready to use.
Press ~ (tilde) or F1 to open/close the console in Play mode.
using UnityEngine;
using PPConsole;
public class GameManager : MonoBehaviour
{
private int playerHealth = 100;
[Command("GetHealth", Description = "Shows current player health")]
private void GetHealth()
{
ConsoleManager.Instance.Log($"Health: {playerHealth}");
}
[Command("SetHealth", Description = "Sets player health to specified amount")]
private void SetHealth(int amount)
{
playerHealth = amount;
ConsoleManager.Instance.Log($"Health set to {playerHealth}");
}
}That's all you need! The console will automatically discover and register these commands when the scene loads.
Open the console and type:
GetHealth
SetHealth 75
Commands are created by adding the [Command] attribute to any method:
using PPConsole;
public class ExampleCommands : MonoBehaviour
{
// Basic command - no parameters
[Command("SayHello", Description = "Prints a greeting")]
private void SayHello()
{
ConsoleManager.Instance.Log("Hello, World!");
}
// Command with parameters
[Command("Teleport", Description = "Teleports player to coordinates")]
private void Teleport(float x, float y, float z)
{
transform.position = new Vector3(x, y, z);
ConsoleManager.Instance.Log($"Teleported to ({x}, {y}, {z})");
}
// Command with string parameter (use quotes for spaces)
[Command("Say", Description = "Makes character speak")]
private void Say(string message)
{
ConsoleManager.Instance.Log($"Character says: '{message}'");
}
}For string arguments containing spaces, use quotes:
Say "Hello World"
Teleport 10 5 20
The console automatically converts arguments to these types:
stringint,longfloat,doubleboolenumtypes- Any type supported by
Convert.ChangeType()
By default, commands are stripped from production builds and only available in the Unity Editor or Development Builds. This protects sensitive developer commands:
// This command will be stripped from production builds (default behavior)
[Command("GodMode", Description = "Toggles invincibility")]
private void ToggleGodMode(bool enabled)
{
// Only available in Editor/Development builds
}
// Set strip: false to keep command in all builds
[Command("GetVersion", strip: false, Description = "Shows game version")]
private void GetVersion()
{
ConsoleManager.Instance.Log($"Version: {Application.version}");
// Available in all builds, including production
}Strip Parameter:
strip: true(default) - Command only available in Editor/Development buildsstrip: false- Command available in all builds including production
Static methods can also be commands and don't require an instance:
[Command("QuitGame", strip: false, Description = "Exits the application")]
private static void QuitGame()
{
ConsoleManager.Instance.Log("Quitting...");
Application.Quit();
}For non-MonoBehaviour classes or runtime registration:
public class CustomCommands
{
[Command("CustomCommand")]
private void MyCommand()
{
// Command logic
}
}
// Register manually
var customCommands = new CustomCommands();
ConsoleManager.Instance.RegisterCommandsFromObject(customCommands);The console includes these commands out of the box:
| Command | Description |
|---|---|
help |
Lists all available commands with their signatures |
clear |
Clears the console output |
echo <text> |
Echoes back the provided text |
history |
Shows command history |
The console UI can be customized by editing the ConsoleUI prefab:
- Change colors, fonts, and sizes in the TextMeshPro components
- Modify the panel background, opacity, and layout
- Adjust the scroll view behavior
Adjust settings in the ConsoleUI component:
- Max Log Entries - Maximum number of log entries to keep (default: 500)
Log messages to the console from anywhere in your code:
ConsoleManager.Instance.Log("This is a normal message");
ConsoleManager.Instance.LogWarning("This is a warning");
ConsoleManager.Instance.LogError("This is an error");ConsoleManager- Singleton that manages command registration, discovery, and executionConsoleUI- UI component that renders the console and handles user inputCommandAttribute- Attribute to mark methods as console commandsCommandInfo- Internal class that stores command metadata
The console automatically discovers commands in two ways:
- Static Methods - Scans all assemblies for static methods with
[Command]attribute - Instance Methods - Finds all MonoBehaviours in the scene and scans them for
[Command]methods
Commands are discovered during Start() after all Awake() and OnEnable() calls have completed.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Clone the repository
- Open the project in Unity 2021.3 or later
- Open the
DemoSceneinSamples/Scenes/to see examples - Make your changes and test thoroughly
- Follow existing code style and conventions
- Add XML documentation comments to public APIs
- Test changes in both Editor and builds
- Update README if adding new features
This project is licensed under the MIT License - see the LICENSE file for details.
Future features:
- Autocomplete suggestions
Made with ❤️ by PlayerMadeGames