A dev console built for Unity. Developers can create commands and enter them during gameplay.
This was originally developed for The Story of Kate Webster to help with testing. This project is seperated from that game into a standalone Unity project with a demo scene.
- Configurable combination to open the console
- Escape to close the console
- TMP input and output
- Seperate command components
- Automatic command detection
- Help command
- Clear command
- Command creation menu and a script template
- Arguments
- Console opening for editor and development builds
The project uses Unity 6000.3.19f1
Dependencies
- Unity Input System
- TextMeshPro
The required packages are saved in Packages/manifest.json. Unity will restore them when opening the project.
Clone the full project
git clone https://github.com/AlekMunroe/Unity-Dev-Console-System.git
- Open Unity Hub
- Add the cloned folder
- Open it in Unity
6000.3.19f1. - Allow Unity to import assets and restore packages
- Check the console for errors
Use in existing project
- Download the
.unitypackagefile - In Unity go to
Assets > Import Package > Custom Package - Select the downloaded
.unitypackagefile - Click Import and keep the files in
Assets/DevConsole - Drag the prefab in
Assets/DevConsole/Prefabsinto your scene
Try the demo in Assets/DevConsole/Demo and enter Play Mode.
The command creation script expects a template at
Assets/DevConsole/Editor/Templates/DEV_CommandTemplate.txt
See Developer guide for how to create custom commands.
The scene requires:
- A console panel with TextMeshPro output and an input field
- An active GameObject with Dev_ConsoleController and Dev_ToggleConsole
- A Commands GameObject with the command components
- An EventSystem using the Input System UI Input Module
on DEV_ConsoleController assign:
| Field | Assign |
|---|---|
| Output Text | TextMeshPro Text component to show the output |
| Input Box | TextMeshPro Input to type commands |
| Commands Object | GameObject with command components attached |
On DEV_ToggleConsole assign:
| Field | Assign |
|---|---|
| Dev Console | Panel to show/hide |
| Input Box | The same input assigned to DEV_ConsoleController |
| Required Keys | Keys which are held together to open the console |
Attach ClearCommand and HelpCommand to the Commands GameObject
- Enter Play Mode
- Hold all the keys set in Required Keys
- Type a command
- Press enter to send the command
- Press Esc to close the console
| Command | What it does |
|---|---|
| clear | Clears the console output |
| help | List the commands and their descriptions |
| help | Shows a specific command's description and its usage |
Example:
help clear
Output:
clear
Description: Clears the console
Usage: clear
Commands are not case sensitive.
The system uses three parts
- DEV_ToggleConsole: Uses the set keys to show the console panel
- DEV_ConsoleController: Runs commands, reads inputs and runs the correct commands
- DEV_ConsoleCommand: Handles the shared structure which is inherited by commands
The command flow:
Input > Command > Registered command > Execute
The controller finds each command component which is attached directly on the Commands GameObject on start.
Each command contains:
- CommandName
- Description
- Usage
- Execute
The command handles its own data and behaviour.
Assets/
└── DevConsole/
├── Commands/
│ ├── ClearCommand.cs
│ └── HelpCommand.cs
├── Editor/
│ ├── DEV_CommandCreator.cs
│ ├── Templates/
│ └── DEV_CommandTemplate.txt
├── DEV_ConsoleCommand.cs
├── DEV_ConsoleController.cs
└── DEV_ToggleConsole.cs
- In the project window, right click in the Commands folder
- Select
Create > DevConsole > New Command - Name the script
- Customise CommandName, Description and Usage
- Add custom behaviour inside Execute()
- Drag the script into the Commands GameObject
The command script must be on the Commands as a component.
See Developer guide for the hello world command example.
- Check the opening script is on a GameObject outside of the hidden panel
- Check the references and Required Keys are set.
- Check the scene has an EventSystem using the Input System UI Input Module.
- Check Active Input Handling supports the Input System.
- Check the script is on the Commands GameObject and it is enabled.
- Check the CommandName and look for errors in Unity's console.
- Two commands have the same CommandName.
- Give each command a unique name.
- Check DEV_CommandCreator is in the Editor folder.
- Check the template is in
Assets/DevConsole/Editor/Templates/DEV_CommandTemplate.txt
Alek Paul Munroe