When is it appropriate for code to be written in the controller and when is it in the character?

Hello all, I am just starting out with Unreal with zero background in game development.

I see a lot of samples that seem to put user movement and action code within the character class while some put them into the controller class.

As the title of the question would suggest, I am unsure on when is it best to put this code into the controller and when is it good to put into the character classes.

Can you folks give me a rough guideline on what is proper or perhaps point me towards articles that cover this.

Thanks.

Control stuff like movement or functions you need for the hud later should go into the controller, variables that are important for gameplay should go into the character, especially for multiplayer setups since you’d not want to necessarily share each others controllers over the network, although I suppose you can put gamelogic in the controller as well.

Also very much depends on your goals I suppose, my “playercharacter” is the basis for many of the npcs that are equal in stats and abilities to the player so they have to be able to access their variables without a player controller and it would not be efficient to put the same thing into an AIController.

Some things are very specific to the controller, like mousecontrol, click events etc.

Hope that clears it up a bit, although it’s very much just personal preference for me.

Hey benjamin,

I would recommend taking a look at the example projects in the market. Specifically the “Shooter Example”. It’s a fully functional multiplayer FPS in c++. You could see how they use these two classes and get an idea of what functionality is best for each class.

you always have a valid player controller, but you might not always have a pawn.

ask yourself, what happens if my character dies or falls out of the world or if the player switches characters?

what information should stay with the player? what information should die with the character?

so for example: the HUD is owned by the player controller instead of the pawn character, because if you died and wanted to display a game over message before you respawned, you wouldn’t have access to your pawn’s HUD, because you don’t have a pawn anymore.

imagine a turn based RPG like final fantasy. in battle, you have 3 characters, and each of those characters have their own attacks, mana, and health, but they all share an inventory of items. the item inventory would be in the player controller, while the attack choices would be defined in each pawn/character.