Since RTS Games are very popular and most of them need a proper command system, I thought it would be good to collect ideas and in the end provide
a tutorial or documentation for UE4 to simply build one.
Maybe all of you who are interested post and discuss about ideas.
Let me begin:
There is an interface: ICommandableActor
It provides methods that commandable actors must implement.
So every actor can implement a command in its own way, that’s very good and dynamic.
Those methods are:
TArray<FString> GetSortedSupportedCommandList(); // returns an array of strings which specify the name of the command they support (sorted (see next method) ) bool IsCommandExecutionPossible(uint16 index); // specifies, whether the command with the given index can currently be executed (call regularly to set a disabled texture) bool IsCommandTargetValid(AActor* target, uint16 index) // same as above, changes cursor to forbidden or something like that void ExecuteCommand(uint16 index, AActor* target, FVector3 pos) // Executes the command at given index, target and position uint16 GetDefaultCommand(AActor* target) // returns the index of the default command executed on the given target (move on the ground, attack on enemies, repair on damaged structures,...)
To the indices: The returned list is sorted by index. When the player clicks a command in the UI, the index of the command in the UI is retrieved and passed to the ExecuteCommand method.
This method knows which function or command to execute and can do its things.
Subclassing is easy, to extend the available commands, you retrieve the string array from the superclass and append your own ones.
Execution or validation requests can be passed to superclass if it’s its command. Methods then have to be virtual.
These are my first thoughts on this, please respond, and give feedback.