I created subclass of my Blueprint class from c++. And I want to setup properties of the Blueprint subclass like following codes. This codes finished without warning or errors, but value is not set in Editor. How can I do this?
I confirmed I can set property to this subclass in Blueprint Editor manually. But I want do this with C++ plugin because there are so many assets.
void SubBPFactory::SetupSubBP(FString BPName, bool SomePropertyValue)
{
UBlueprint* TargetParentBP = (UBlueprint*)StaticLoadObject(UBlueprint::StaticClass(), NULL, TEXT("/Game/BluePrints/ParentBP"), NULL, LOAD_NoWarn, NULL);
UClass* TargetParentClass = TargetParentBP->GeneratedClass;
UBlueprintFactory* BlueprintFactory = NewObject<UBlueprintFactory>();
BlueprintFactory->ParentClass = TargetParentBP->GeneratedClass;
FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
UObject* newObject = AssetToolsModule.Get().CreateAsset(BPName, TEXT("/Game/BluePrints/SubClasses"), TargetParentBP->GetClass(), BlueprintFactory, FName("CustomNewAsset"));
UBlueprint* NewAsset = Cast<UBlueprint>(newObject);
UBoolProperty * BoolProp = FindField<UBoolProperty>(TargetParentClass, TEXT("SomeProperty"));
if (BoolProp)
{
void* Object = BoolProp->ContainerPtrToValuePtr<void>((void*)newObject);
BoolProp->SetPropertyValue(Object, SomePropertyValue);
}
}