Skip to content

Creating a new command

Anders Magnusson edited this page Apr 24, 2020 · 2 revisions

There are two ways to create a new command: by extending the scriptable object "Command" or by implementing ICommand directly. Below follows the required steps in order to create a new command and make it available in-game.


Method 1: Scriptable object (recommended)

  1. Create a new script in "ScriptableObjects/Console/Commands/"
  2. Make it extend and implement the abstract class "Command"
  3. In the "Execute" method, add your own logic and send back any relevant message with "sender.SendMessage"
  4. Add the attribute [CreateAssetMenu(menuName = "Console/Commands/YourCommandName")] above the class
  5. Navigate to "Gameplay/Console/Commands/", right click and click "Create>Console>Commands>YourCommandName"
  6. Select the new command asset and put in appropritate values in the inspector
  7. Navigate to "Gameplay/Console/CommandCollection" and drag and drop in the new command asset

Method 2: Manual script

  1. Create a new script in "Scripts/Console/Commands/"
  2. Make it implement the interface "ICommand"
  3. Add your own logic
  4. Access the active "CommandManager" and call "Register(new YourCommandName())"

Clone this wiki locally