A new system is in place to allow for the addition of custom console commands in blueprints. Here are the steps to set this up:
Create a new blueprint class that inherits from the UDataActorCommand code class. This class has a BlueprintImplementableEvent called DoCommand . This is event will be called when the command is executed. All wanted logic should follow this event.
Here is the DoCommand event. It provides three arguments: Parameters, CallingPlayerController and World
Parameters is an array of strings. When typing the command in to the console, you can also type in some strings after the name of the command. These strings will be put into an array and fed in to the event. It is up to you to parse through these strings, and convert them to ints, floats, etc. if necessary. The above example simply loops through each parameter and prints it to the screen.
CallingPlayerController is a reference to the player controller object that is calling the cheat command. It is there to provide convenient access to the player calling the command, and as a convenient WorldContextObject.
World is reference to the world object
Locate and open the CustomConsoleCommandsDataTable . Add a new row to this table. Change the name of this row to the name of your new command. This is what you will type in to the console to call your command. In the CommandActorClass section of the row, select the new blueprint class that you created. When a custom command gets called, the game will use the name of the command typed in to lookup the associated class in this table. One instance of the actor will be spawned (singleton) for the whole server and the client. This one actor will handle all commands of given type.
You can specify network context: client / server. If both are selected, then command will be executed on both sides.
You can specify admin requirements.
Avoid using UDataCommand base type, it’s deprecated because it does no provide full world context.
Once this has all been done, you can now call your new command in game. To call it, start up the game and type in the console:
DataCmd
CommandName Parameter1 Parameter2 Parameter3…
(or)
dc
CommandName Parameter1 Parameter2 Parameter3…
DataCmd is the innate cheat command that will let the game know that we are trying to use a custom command. It is required to have before anything else.
CommandName is the name of your command. Again, this should be the name of the new row you added to the CustomConsoleCommandsDataTable table.
After CommandName, you can type out as many parameters as you want. As stated before, these parameters will get put into a string array that will get passed into the DoCommand event