How to code an rts in ue4

Hey, I’ve been trying to figure out how to code an rts in ue4, and I can’t seem to find a place to start.

I started out with the top down c++ sample, but there are certain things I just can’t seem to figure out. For one thing the top down sample comes with a default player that has a camera attached to it, as well as a player controller, that sort of stuff isn’t very useful for an rts.

Say for a prototype I want to create a simple character class to use for some player units I can control. I want to be able to select a single or multiple units and be able to move them to another part of the map that I click. It sounds simple enough, but where do I start?

Any help would be appreciated, I’m definitely not a beginner when it comes to c++, nor am I asking for code or anything like that, I’m just looking for someone to point me in the right direction. Thanks.

Start with the Strategy Game example on the Market Place.

That’s the first thing I checked out when starting on my project, it has so much extra stuff I don’t need and it doesn’t make for a very good starting point for what I’m trying to do. Thanks though.

You would start with a basic PlayerController which provides you with the information where the player clicks and what is underneath it and which units are currently selected, have a look at:

Start with a real simple setup and where you can select one unit. If you click on that unit, it will be selected. If a unit is selected you can click on the ground and it moves there.

I would use two different Controllers. One if the unit is selected (player input for moving) and one for AI with a simple FSM (attack near targets, otherwise idle).

I would start out with a single unit and extend the code from there.

Maybe this outline will help you a little…

The main problem I’m having is that the camera is attached to the default player class, also, I’m not exactly sure how to determine whether or not what you clicked on is a member of a particular class. The top down sample is basically what I want it to be like except i want the camera to be independent of the player and have to ability to select a single unit or multiple units. I tried some of the suggestions on the last post but now I’m even more confused.

It has a lot of things you’ll probably need at some point though. The problem, for me at least, is that learning from it takes a little bit of time since you have to figure out a lot of things simultaneously.

For example, there’s a nav mesh for the level. This is how the AIControllers for each of the AI pawns navigate. You’ll need that in RTS. The fact that there’s even AIDirector and AIController classes is also useful. You’ll need models with animations eventually. You’ll need a HUD eventually. Looking at the brewery actors and how there’s custom code for it is probably helpful for creating RTS buildings.

Don’t discount it, but I will agree that it’s not ideal.

You should start with getting a notebook and a pen and writing your ideas on paper. What features you want the game to have. What controls the player will have. Create some cursory class diagrams which you can revisit and improve upon later. Start with what you want to work on or what you know you can do, then ease into the harder stuff as you progress.

You don’t always have to dive into the deep end when starting a daunting project.

That was the first thing I did before I even started, I just want to clarify that I’m not a newb or anything. Lack of planning isn’t my problem, its just that I’m not sure how to put my plan into action

The camera gets attached through the Camera Boom setup in the characterClass:

/** Camera boom positioning the camera above the character */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
	TSubobjectPtr<class USpringArmComponent> CameraBoom;

There’s even a comment that says what it does… Actually this shouldn’t be too hard to find… Have a look at the strategy game example to see how to setup a standard rts camera.

Then again, the code is right there in front of you in the strategy game example. You just have to find it and then (the hard part :wink: ) understand it.

It will take some time to get a grasp of how the strategy game works, but if you fully understand what they are doing, you won’t have such a hard time getting the results you described above.

Hey everyone, thanks for the help and suggestions, I’ve been messing around with some code from the strategy game for quite a bit now, and things are finally starting to make sense.

Does anyone know where I can find the strategy game example?
I checked the marketplace but couldn’t find it.

Also, I found a tutorial for a tower defense game: tutorial, but I can’t find the actual project/code used in the tutorial.
Does anyone know where I can download it from?

The “official tutorials/samples” are no longer in the marketplace (for quite some time now I think). If you open the Epic Games Launcher and click on the item between Community and Marketplace on the left (probably called something like Instructions or Tutorials etc.) you can scroll down and find a section with example game projects including the “Strategy Game”.

I found it, thanks!