Creating Commands queue for an RTS

Adding onto the link in the comments…

The core of your problem is you’re going to need a way to define a type that can be organised and called on with parameters with some concept of priority.

First, you want a base “command” type.
There are design patterns you could look to for this sort of thing, but I would avoid looking into those as they will probably result in confusion and unnecessary code.
Keep it simple!
You need a type, we’ll call it RTSCommand.
Your RTSCommand will have an int run() (return 0 for success, other for error), and an int priority.

Each of your commands will be a subclass of RTSCommand.
For example I might have a RTSTrainCommand which will train a unit.
You probably want to add a unit type, so add a text property to the class that is the URL to the Blueprint that is to be spawned after training is complete.
Then your run() function will start a timer and spawn the Blueprint specified in the URL at timeout.

Only thing left is to discuss priority.
Let’s say I add another thing to the queue.
You can add to the end of a list of RTSCommand and that will get the job done nicely, but for a more flexible implementation I’d use the priority value.
The priority queue structure in the standard library works in Unreal C++ at least on Windows machines, but even if it doesn’t it’s very cheap and simple to traverse a small list and figure out which item has the highest priority number.

Make sense? :slight_smile:
For more complicated implementations, you can look to how the C++ standard library does threading, but you’ll be going down one hell of a rabbit hole.