Download

(4.26) Converting from Blueprint to C++ - Stuck on GameMode

I’m currently working through the process of converting a few blueprints to C++. I’ve converted my character, player controller and game state. I have created a gamemode but … it doesn’t seem to be working properly and I’m having the hardest time figuring out why. When I use the blueprint gamemode with my C++ versions of player controller, pawn and gamestate, it works fine. But I swap to a blueprint child of my C++ gamemode using the C++ player controller, pawn and gamestate and it doesn’t seem to create the pawn anymore. I have a feeling there’s stuff I need in my gamemode’s constructor but this seems to have changed dramatically over the years.

I have tried the following

header



#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameMode.h"
#include "MyCPPGameMode.generated.h"

UCLASS()
class GAMETEST_API AMyCPPGameMode : public AGameMode
{
GENERATED_BODY()

public:
AMyCPPGameMode(const FObjectInitializer& ObjectInitializer);
};


cpp



#include "MyCPPGameMode.h"

AMyCPPGameMode::AMyCPPGameMode(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}


Also tried it without a constructor because I guess it’s not needed now? I don’t know… so much mixed information and I have no idea how to start debugging this.

Yes, ObjectInitializer isn’t needed nowadays. You can use it for some advanced stuff, but by default, you don’t need it. There is nothing specific that you have to do in the constructor for GameMode as well. Maybe you’ve just overriden a function without calling Super for it?

Well, I feel like an idiot.

I removed the constructor completely and it works. I swear I tried that before …
Anyway, thanks for the confirmation!