Download

Finding a BP-project's Character/Controller from C++ AGameModeBase

I have a project that I created as a Blueprint project. I want to use a custom Game Mode, and I’ve set all the same ::StaticClass()'s as the default game mode uses. But the PlayerControllerClass and DefaultPawnClass settings elude me, as these exist as blueprint assets. I naively tried:

DefaultPawnClass = LoadClass<APlayerController>(NULL, L"TopDownCharacter", NULL, LOAD_None, NULL);

But it fails to spawn with a warning of

LogUObjectGlobals: Warning: Failed to find object 'Class None.TopDownCharacter'

This is what I would do to set the PlayerController to a Blueprint at the path /Game/Blueprints/GamePC:

    static ConstructorHelpers::FClassFinder<APlayerController> PC_Class(TEXT("/Game/Blueprints/GamePC"));
    if (PC_Class.Succeeded()) {
            PlayerControllerClass = PC_Class.Class;
    }

Put it in the Constructor of your GameMode class.

Hope this helps!