Download

Changing Player Controller on ShooterGame?

I think this is the correct forum for this question…

I am trying to change the player controller in the ShooterGame project to a blueprint one that has a parent of the original c++ class and cant seem to get it right.
I have tried changing it to a blueprint controller whos parent is ShooterPlayerController . Thru my digging I have determined that it is set in the DefaultGame.ini
PlatformPlayerControllerClass=Class’/Script/BeTheLastMan.ShooterPlayerController’
I have tried changing it to a blueprint controller whos parent is ShooterPlayerController
I have tried many different ways to locate it but I think I just cant find the correct path.
PlatformPlayerControllerClass=Class’/Game/Blueprints/Pawns/myPlayerController’
PlatformPlayerControllerClass=/Game/Blueprints/Pawns/myPlayerController
I put a breakpoint in VS2017 on the line that loads the player controller “if (PlatformPlayerControllerClass != nullptr)” and its always Null on the ones I have changed, if I put it to its original line it finds it no problem.
Does anyone know how to change this? I assume its just the way I am editing it… Thanks!

Look at the constructor for AShooterGameMode in ShooterGameMode.cpp. It’s setting the PlayerControllerClass to AShooterPlayerController there:


PlayerControllerClass = AShooterPlayerController::StaticClass();

This was it, thank you!
I am not a programmer, know just enough to get myself in trouble. I followed how the other classes were being found from that same file and added this


static ConstructorHelpers::FClassFinder<APlayerController> myControllerOb(TEXT("/Game/Blueprints/Pawns/myPlayerController"));
	myControllerClass = myControllerOb.Class;

	//PlayerControllerClass = AShooterPlayerController::StaticClass();
	PlayerControllerClass = myControllerClass;

Is that the correct way to do it? Seems to work :wink:
Thanks again!

You can do it that way, but in general it’s bad practice to reference blueprint assets from code (you should only really do it as a last resort).

A better approach is to create a Blueprint of the GameMode, then in that Blueprint you can set your custom player controller. Blueprints that are data-only assets have zero performance overhead, and you get all the benefits of nicely managed references etc.

Good to know, thanks.
Its a blueprint based inventory system, as I level up my programming the idea is to transfer it directly to the characters code as I know that everything runs better in native code.

That’s not strictly true - blueprint is very much part of the UE4 pipeline, and you should rarely if ever reference BP assets in code where possible.