Hey Dominik,
I don’t know if you still need an answer but I think I have one for you because I needed the same thing and I just found out how it works.
My setup is just like yours that I also have a custom button in the editor and as soon as I press it I do the following in the clicked method:
UWorld* const World = GEditor->GetEditorWorldContext().World(); // Get a world reference
AWorldSettings* worldSettings = World->GetWorldSettings(); // Get the world's settings
worldSettings->DefaultGameMode = PluginManager::getInstance()->getGameModeClass();
The PluginManager here is a Singleton class that stores all the important information about my plugin that I need all the time - e.g. my gamemodeclass…
The getInstance() looks like this:
static PluginManager* getInstance()
{
return (!instance) ? instance = new PluginManager() : instance;
}
The getGameModeClass() looks like this:
TSubclassOf<class AMyGameMode> getGameModeClass() const
{
return this->gameModeClass;
}
The setter looks like this:
void setGameModeClass(TSubclassOf<AMyGameMode> gameModeClass)
{
this->gameModeClass = gameModeClass;
}
The member itself looks like this:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) TSubclassOf<class AMyGameMode> gameModeClass = nullptr;
I did the assignment inside the constructor of my gamemode, because it is executed when starting the editor and I then already have a reference to the class without having to find it with the ClassFinder:
PluginManager::getInstance()->setGameModeClass(this->StaticClass());
This works if your GameMode is a C++ class. I guess if your GameMode is a BluePrint, you would have to get the Class like this:
static ConstructorHelpers::FClassFinder<AGameMode> GameModeBPClassFinder(TEXT("/Plugin/GameModeBP"));
if (GameModeBPClassFinder.Class != nullptr)
{
PluginManager::getInstance()->setGameModeClass(GameModeBPClassFinder.Class);
}
If you still have questions feel free to ask.
Joey