Why does my Gamemode classes reset to default on editor startup?

Hey, i’m having some trouble with my gamemode at the moment. I have a gamemode class in C++ in which i set the default pawn class and the player controller class. But each time i start the editor the two classes that i set are reset to the default value. But they have that small yellow arrow to reset the value back to the classes that were set using C++.

The gamemode blueprint.

The world settings

Maps and Modes, project settings

And the code in the gamemode class.

AHomeInvasionGameMode::AHomeInvasionGameMode(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
	// set default pawn class to our Blueprinted character
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/Blueprints/Player/BP_FPSCharacter"));
	if (PlayerPawnBPClass.Class != NULL)
		DefaultPawnClass = PlayerPawnBPClass.Class;

	// Set default player controller class to our blueprint
	static ConstructorHelpers::FClassFinder<APlayerController> ControllerBPClass(TEXT("/Game/Blueprints/General/BP_PlayerController"));
	if (ControllerBPClass.Class != NULL)
		PlayerControllerClass = ControllerBPClass.Class;

Just out of curiosity, what happens if you skip the NULL-checks?

To find out where the values are being set use a memory breakpoint - this is how you do it in visual studio:

  1. put a normal breakpoint in the constructor

  2. when paused there get the address of a variable that is being set (for instance put &PlayerControllerClass in a watch window).

  3. take the hex value for that variable address and…

  4. … open the breakpoints window, then select “New Data Breakpoint” from the dropdown in the top left

  5. enter the hex address

  6. continue debugging (f5). The program should pause again when something edits the value of that variable

My guess is that the blueprint defaults are overriding the C++ defaults somewhere in the actor spawning code and you should move the assignment to some other function (InitGame perhaps?).

Hey, i did some testing following your instructions but was unable to find where the values were set back to the defaults. I tried moving the code to InitGame but it just crashes when the game is started.

I also tried moving the order which the values are set (switching place of the pawn and controller code so that the controller is first) which for some reason fixes it for the player controller and it is always set after starting the editor, the pawn class is still set to the default value.

So the data breakpoints didn’t fire at all? Are the values seen to change in the debugger between initialization and runtime? If so I’d expect the data breakpoint to tell you where - while they can have some caveats on some architectures I’ve found them pretty easy to use on PC in Unreal. If not then that’s probably a clue about something!

Swapping the order doesn’t changing behavior doesn’t make sense to me, but I don’t really know the initialization process very well, just having delved to solve my own problems.

Nor does moving the code to InitGame causing crashes, unless you moved the construction helper which only seems to work during construction :slight_smile:

     static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/Blueprints/Player/BP_FPSCharacter"));
     if (PlayerPawnBPClass.Class != NULL)
         TmpVariableNotAUPROPERTYPerhapsAStatiCDefaultPawnClass = PlayerPawnBPClass.Class;

DefaultPawnClass = TmpVariableNotAUPROPERTYPerhapsAStatiCDefaultPawnClass;