Why Player Controller?

Why do we use player controller since we can write whole player code in it’s own class. Why do we create player controller. Does it make any difference? Why should I use one?
Thank You

The PlayerController is basically an abstraction for the player. Not the representation of the player in your world but the actual player. Think of the Pawn as the in-world representation of the player and the Controller as the “will” or the “brain” that drives it.

A PlayerController is what you’ll get as reference when joining a multiplayer game, so you can assign it a pawn. In MP, the controller persists throughout the game while the Pawn can be transient. It is also where you can store data that needs to persist throughout the death of your character.

It’s fine to handle input in the Character. It’s a natural way to think of things, especially for less complex cases. If you have more complex needs though, like multiple players on one game client or the ability to change characters dynamically at runtime, you might be better off keeping your input in the PlayerController.

1 Like

You mean Player Controller keeps the data safe even if player leaves the game world or gets destroyed?

No, the only class keeping data between levels is the game instance.

If the Pawn get destroyed the controller can unpossess the pawn and possess another one or used to control UMG for example

1 Like

Game instance???
So Player Controller is never free? It always takes inputs?

GameInstance: high-level manager object for an instance of the running game. (Source UE4 doc)
The game instance is a manager class that is not destroyed when changing levels in your game . This means data such as player health, score, ammo and more can be stored between levels. The data is kept as long as the game is running. Really useful in multiplayer with function like server travel for example. Once you close your game the data is lost. You can change the default game instance in the project settings if you create one.

I’m not sure to understand the question but you can use a player controller alone for certain kind of game.

You can always bind input in the player controller.

1 Like

OK. Thank You so much.

1 Like