Hi all,
I’m trying to build an editor tool intended to generate Blueprint .uassets for designers to use in levels. Working on proof of concept with a Player Controller, and Game Mode, and I’ve hit an interesting snag, which I want to try and solve now because I anticipate needing to know it in future.
At a high level, I’m trying to:
- APlayerController* NewPlayerController = NewObject<PlayerController>(…)
- UBlueprint* NewPCBlueprint = FKismetEditorUtilities::CreateBlueprintFromActor(…)
- AGameModeBase* NewGameMode = NewObject<PlayerController>(…)
- NewGameMode->PlayerControllerClass = <<Get NewPlayerController_BP .uasset class!>>
Which results in:
But of course, I don’t want to add the class UBlueprint… I want to add the actual generated blueprint’s class, as if I had picked it from the ClassViewer…:
This is what I’ve cobbled together to try and assign the PlayerController to the GameMode, in code:
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
FAssetData PCAssetData = AssetRegistryModule.Get().GetAssetByObjectPath(*(PlayerControllerBPPathInfo.PackageNameString + FString(TEXT(".")) + PlayerControllerBPPathInfo.AssetName.ToString()), false);
OutGameModeToModify->PlayerControllerClass = PCAssetData.GetAsset()->GetClass();
Where “PlayerControllerBPPathInfo.PackageNameString + FString(TEXT(”.")) + PlayerControllerBPPathInfo.AssetName.ToString()" is “/Game/IDTPlayerController_BP.IDTPlayerController_BP”
Help, please and thanks!