Set different playercontroller in game mode

I made a new c++ project and started the c++ programming tutorial. Now I want to increment an integer variable whenever I click on my actor.

I googled a bit and apparently I have to enable mouse input in the player controller. I made a new one since I didn’t have it already. Now I need to set the player controller in the game mode. I can’t edit the player controller with project settings - maps & modes (everything is greyed out). I’m guessing that is because it is a c++ project. So I have to change the playercontroller in my gamemode.cpp file? There’s no playercontroller variable or a setplayercontroller function as far as i know, so how do I do this?

Or would it be better to make a new blueprint gamemode and set a blueprint playercontroller in the project settings?

thanks.

#Wiki For You

I have a wiki on exactly this subject :slight_smile:

This is a C++ solution

Linking Custom Player Controller to Game Mode

Rama

Hi Rama,

Thanks for the article! I have a few questions though.
My player controller blueprint is called MyPlayerController so I changed the type from AYourPlayerController to AMyPlayerController, but it says it’s undefined?

Where do I put the code? My cpp is just an empty file apart from a few includes, do I need to override a function?

It sounds like you need to include your MyPlayerController class’ header file. Search for “class AMyPlayerController” and include the file that this class is declared in. If you search for “class AMyPlayerController” and it isn’t found, then you haven’t created that class anywhere.

I have the same issue. It seems the FPostConstructInitializeProperties not defined. I noticed your YourPlayerController.h not declare AYourPlayerController(), do i miss something?

Hi Rama,

  1. Once I have set the player controller class per the Wiki, I still need to spawn the new player controller - right?
  2. This Wiki uses FObjectFinder. Could we avoid that and use a UPROPERTY( … and TSubClassOf and assign the object in the Editor? If so, how would that work (I tried without success …)