How do I specify my controller and pawn in a c++ game Mode class?

I’ve created a game mode class where I intend to spawn level geometry before the player enters the level. I had setup a gamemode BP in UE4 that selected the default pawn and player controller. Right now when I switch to my c++ game mode class those selections no longer exist.

How can I specify in my c++ game mode class which default pawn and player controller and or, if it makes more sense, how can I link it to the already existing gamemode BP class I’ve created where these items are already specified?

Additionally, is it possible to link my c++ game mode class in the gamemode.ini so that it defaults to it?


1 Like

You set default variables in constructor, the variables you search for in AGameMode, they are called DefaultPawnClass and PlayerControllerClass, thy waiting for UClass pointer and you can get that pointer from any UObject class using static function called StaticClass(). UClass pointer are equivlent of purple color types in Blueprint. So you simply add this to your AGameMode constructor:

DefaultPawnClass = ASomePawn::StaticClass();
PlayerControllerClass = ASomePlayerController::StaticClass();

Just replace class names :slight_smile:

1 Like

Thanks! Is it possible to link this to already existing BP classes that I’ve already assembled? For instance I have a player controller BP class all ready. How would I go about linking that to my Game Mode c++ Class?

Sorry, I’m a little confused. How do I get those “ASomePawn” and “ASomePlayerController” ?

Those are C++ classes, if you got you Pawn and PlayerController in C++ you can directly reference them like that. Getting UClass from blueprint is tricker, you need to do something like this:

static ConstructorHelpers::FObjectFinder<UBlueprint> Blueprint(TEXT("Blueprint'/Refrence/Path/To.Blueprint'"));
     if (Blueprint.Object){
         DefaultPawnClass = (UClass*)Blueprint.Object->GeneratedClass;

You get refrence path by rughtclicking blueprint and clicking “Copy Refrence” and it will give you path to clipboard (like copy paste)

But i know people have problems when they package something like this so im not sure, i know some people use FObjectFinder, so maybe search for that

You are awesome, thank you very much. That worked perfectly. Yeah the problem is that I plan on using many blueprints in combination with programming, I’m not the best programmer so I need to rely on the editor side of things for most, but have specific needs that require me to stub my toe through the programming. The first way would have been much easier if I had a Character.h to reference and then I could have done that, but I’ve already assembled my default pawn/ player controller/ camera, etc… all in BP.

Anyhow that worked perfectly, thanks again!

Is it possible to use specifiers (or something else?) in order to make c++ gamemode properties editable in the Unreal Editor? Like default pawn…

I have set up my UMG and I want a pawn to be possessed by Boolean and spawn in to the world. My set up is like “”. If I was to assign to bool. How would I get the starting location for my pawn in Blueprints?