Download

Get Class from Blueprint .uasset for use as reference in GameMode

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:

  1. APlayerController* NewPlayerController = NewObject<PlayerController>(…)
  2. UBlueprint* NewPCBlueprint = FKismetEditorUtilities::CreateBlueprintFromActor(…)
  3. AGameModeBase* NewGameMode = NewObject<PlayerController>(…)
  4. NewGameMode->PlayerControllerClass = <<Get NewPlayerController_BP .uasset class!>>

Which results in:

gamemodebp.png

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…:

gamemodebpdesired.png

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!

Hello future internet people!

In the end, I was able to get it to work correctly with the UBlueprint* GeneratedClass as TSubclassOf<T>


TSubclassOf<APawn> NewPawn = CharacterBlueprint->GeneratedClass;
OutGameModeToModify->DefaultPawnClass = NewPawn;

fixed.png