Beginner Question - PlayerController

Hey Everyone,

I am a beginner to UE4 and am trying to create a simple 2D Side Scroller type game to learn the engine. As a programmer, I would like to take advantage of UE4’s C++ functionality rather than just purely blueprints (although it seems like you would generally be taking advantage of both). Right now I’m just trying to get my feet wet by recreating something like the 2D Side-Scroller Template Project (the code version) that comes with UE4 in order to get a handle on the basic architecture of the engine and then build off of that.

I am currently trying to set up my player character and am pretty confused around the “PlayerController” aspect of the Character. I have read how the architecture works and that all makes sense to me but it seems like the template projects (First-Person, Third-Person, Side-Scroller) do not have a “PlayerController” class anywhere yet the player input still obviously controls the characters somehow. I’ve been following the Setting Up a Character guide and under the “Setting Up a Player Controller” section it says:

However, I cannot seem to find this PlayerController either as a C++ ‘script’ or a Blueprint. I’m not sure if I just don’t understand how this works or I am missing something or the projects have changed since this guide was created. If anyone could shed any light on how these classes work together or what is going on in these template projects, I would really appreciate it.

You are correct that Epic is not currently including a PlayerController blueprint, and I do think they should address this post of yours :slight_smile:

I agree that all the templates should come with a blueprinted PC :slight_smile:

I can verify for a fact that the 3rd person C++ template does not come with a PC BP

I was going to mention it on answerhub but you’ve posted this, sooo let’s wait for it to get some Epic attention :slight_smile:

Glad to know I’m not the only one! If I figure out any thing else on this I’ll post back since it seems like others may be having trouble with this.

As a general rule, a PlayerController is always present simply because you can think of the PlayerController as the player themselves. A Character/Pawn is a physical being, while a controller is the “mind” of it. The “mind”/controller tells the Pawn/Character/Physical Being what to do. So, the Controller dictates the Pawn.

With that said. The sample games are not blue-printing the controller, simply because they’re not changing or adding functionality from the default behavior. So no need to add a custom class that changes absolutely nothing from its parent class.

This is why your Inputs are still being processed among other things. When you create a new GameMode, if you go into Project Settings > Maps & Modes and then check out the Default Modes, you can use the drop-down box of “Selected GameMode” and you will see that there is indeed a PlayerController class already setup by default, which should be that of “PlayerController”

Hope that helps!

If you’re searching for the cpp file that controls the character you may be falling into the same pit I did (I also just started and figured I would mess around with double jumping in the side scrolling template)

You have to build the engine from source (AKA clone the github repo or download the source.zip and build) to get the source files for CharacterMovement, they aren’t available in the pre-built engine.

I think you may be getting confused by the name ‘PlayerController’, sorry about that! This is not where the movement logic lives. A ‘controller’ represents a ‘will’ in the game that can ‘possess’ a pawn to control it. A controller could be an AI or a real player, hence the terms AIController and PlayerController. This doc gives an overview of our architecture: https://docs.unrealengine.com/latest/INT/Programming/Gameplay/Framework/index.html

To get a basic game up and running, you only really need the Pawn class. It’s the Pawn class that handles the input and moves itself around. Character is a special type of Pawn which includes ‘walking’ movement logic, and is used as the basis for templates like the side-scroller. You only really need to create your own PlayerController to handle logic outside of the Pawn, things like bringing up a mid-game menu for example. Our Character class is quite flexible, there are some great tutorials and example out there of extending it to add dodge, climbing etc. In 4.2 we made it even easier to do things like double jump, and we’ll be releasing a video tutorial to cover that.

Just…wow, just that statement alone has made a few things click for me. Thank you for that, a good reminder to reread the stuff I read first after having read all the other stuff since…or something like that.

So basically, putting custom movement code directly into my character class is the way to go, right? And, this part of the documentation “each Controller controls only one Pawn at any given time. This is acceptable for most types of games, but may need to be adjusted as certain types of games, such as real-time strategy, may require the ability to control multiple entities at once.” Somewhat trying to wrap my tiny little brain around this. Does this mean that if we had a swarm of bots, we’d have to do some sort of constant cycling of possess/unpossess in order for each to use the functions in the controller?

This made me understand how the system was intended, thanks for the explanation!

Thanks for the replies everyone it’s starting to make a bit more sense. So for a simple sidescrolling game, I wouldn’t need to create a custom PlayerController for any of the basic gameplay mechanics relating to my Character.

For example I want to add features like:
-Double Jump
-Wall Slide
-Wall Jump
-Crouch/Slide
-etc.

This would all be done in my inherited Character class then as my PlayerController is simply just “possessing” my Character when gameplay is happening, which at this stage of development is all that is ever happening. I hit “play” and the PlayerController possesses the “Character” pawn and then you control the character on whatever level is loaded. But if, for example, I wanted to create another level, I would need to create a new PlayerController to handle the player’s will OUTSIDE of the actual gameplay relating to the “Character” pawn (i.e. selecting which level I want to play, bringing up a menu in game to do so, navigating around the game etc.) Then when the level I want to play is loaded up, my Character is spawned and my PlayerController possesses said Character. Similarly if I had enemies in the level, they would also be spawned and AIControllers would possess them.

Let me know if I’m not understanding this correctly, I really appreciate everyone’s help.

In GameMode.h you’ll find the PlayerController object used by the game.

The value of PlayerControllerClass is set in AGameMode’s constructor.

To use/define your own PlayerController, what you’ll want to do, is subclass APlayerController, and subclass AGameMode, and in YourDerivedGameMode’s constructor…

Build your project and launch the Editor. In the “project properties” set your level’s default game mode to YourDerivedGameMode. That’s it, now the game will use your derived player controller instead of the default one. The technique used is called Polymorphism, a common thread in UE4 development.

To handle menus and what not with the PlayerController as you want, you would use a different level for your menu screen, which could have a different GameMode with a different PlayerContorller with the functionality you were wanting. Once the gameplay level loaded and gameplay started, the GameMode and thus the PlayerController would also change accordingly.

1 Like

Might you have a link to any of those? =)

That sounds right!

This was very helpful thank you! I think that I understand how to set up a custom player controller in code now. The main area of confusion that I am having with the player controller is what it is actually used for. Or more specifically, what my custom PlayerController’s purpose is in the whole scope of the game (or just any given game project in general). What would one example of it’s usage be? It seems like all the features that I am implementing I can just do with my inherited Character class, and I am afraid that I am missing an important concept of how the engine works, and how it was intended to be used.

Thanks again for your reply, it was very helpful.

I am actually looking through the Unreal Tournament code and it is providing a lot of insight on how these classes are used together. For anyone else confused on this I would recommend checking it out.

I 2nd this!

You two may want to check out A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums. and I and a few others have contributed to a large amount of tutorials both on the wiki and even on these as well as the answer hub… though mostly , ha.

The documentation Unreal Engine 5.3 Documentation | Unreal Engine 5.3 Documentation is vital to success in understanding how the engine works. Once you’ve got the basic run-down you can pretty much go in any direction whether you use blue-prints or C++.

Or just feel free to PM any of us and we’ll likely get back to you ASAP(As soon as possible)… though it’s also a great idea to put it on the AnswerHub as most of our messages tend to get flooded which won’t allow you to send us any messages and it would help other people who might want to know the answer to it.

DON’T FEEL ASHAMED TO ASK! It’s the only way we can learn. :slight_smile:

this is getting very confusing .
i don’t know what to do ?..
is it possible for an stranger like me to enter the unrealengine zone at all ???
i almost studied any topic about importing a character and make it playable .
after the docs i open the editor and start looking for the names and can not find anything that was named like ‘Player Controller’ . any help is great guys .
my animations are ready . i am trying to make my custom character play around the editor but looks i cant find how …

can any oun give us a good direct step by step ??

Did you check out this video series?

solved , not with that video … i saw all epic character videos :slight_smile: