Add component to blueprint in c++

For anyone look for a solution for this, the code below seems to work for me in 4.19.




//Creating a blueprint

UBlueprintFactory* Factory = NewObject<UBlueprintFactory>();
IAssetTools& AssetTools = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools").Get();

UObject* Object = nullptr;
Object = AssetTools.CreateAsset(
NewFileName,
NewFilePath,
UBlueprint::StaticClass(),
Cast<UFactory>(Factory)
);

UBlueprint* Blueprint = Cast<UBlueprint>(Object);

// Adding a Hierarichal Instance Static Mesh, but I believe this can be any actorcomponents (Not tried)

USCS_Node* Node = Blueprint->SimpleConstructionScript->CreateNode(UHierarchicalInstancedStaticMeshComponent::StaticClass(), TEXT("HISM"));
Blueprint->SimpleConstructionScript->AddNode(Node);
FKismetEditorUtilities::CompileBlueprint(Blueprint);



Hope this helps someone.

Regards
Raz

1 Like