Hi,
I have a button that creates a new blueprint with a class called FbxBuilder and I am trying to add components to that created blueprint but can’t seem to get it to work.
Here is my code:
(This runs when button is clicked):
FString NameStr = "/Game/Blueprint";
UPackage* myPackage = CreatePackage(NULL, *NameStr);
UBlueprintFactory* BlueprintFactory = NewObject<UBlueprintFactory>();
BlueprintFactory->ParentClass = AFbxBlueprints::StaticClass();
FString CallingContext = "";
UBlueprint* MyAsset = Cast<UBlueprint>(BlueprintFactory->FactoryCreateNew(UBlueprint::StaticClass(), myPackage, NAME_None, RF_Public | RF_Standalone, NULL, GWarn, FName(*CallingContext)));
if (MyAsset)
{
// Notify the asset registry
FAssetRegistryModule::AssetCreated(MyAsset);
// Mark the package dirty...
MyAsset->MarkPackageDirty();
}
AFbxBlueprints* myBP = (AFbxBlueprints*)MyAsset->GetBlueprintClass();
myBp->FbxBpMaker();
That last line calls my FbxBlueprints class (the class of the blueprint) and here is the code for that:
AFbxBlueprints::AFbxBlueprints(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
BpRoot = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("Root"));
RootComponent = BpRoot;
}
void AFbxBlueprints::FbxBpMaker()
{
FName MeshName("MYMESH");
MyMesh = NewNamedObject<UStaticMeshComponent>(this, MeshName);
MyMesh->RegisterComponent();
MyMesh->AttachTo(RootComponent);
}
The reason I am doing this is that I am hoping to be able to do a ‘for’ loop and create as many StaticMeshComponents as I need.
The code compiles fine but when I do a Debug->Start New Instance from VS 2013 and click the button, I get a breakpoint from the RegisterComponent() at this location:
void UActorComponent::RegisterComponent()
{
AActor* MyOwner = GetOwner();
if (ensure(MyOwner && MyOwner->GetWorld()))
{
RegisterComponentWithWorld(MyOwner->GetWorld());
}
}
I’ve tried a bunch of different things to get this to add a StaticMeshComponent, but nothing seems to work…any ideas?
Thanks in advance,
-Tim
PS - I am running this in ver. 4.8