I’m working on a scripted asset action for right clicking on a static mesh and creating an actor with the static mesh component added as the root. It’s meant as a quick script to speed up work when prototyping a level and we need an actor that contains a static mesh.
So far I have everything working, except for the part where I add the component. I’m trying to create it as if it was added in blueprint, so I want the component to be editable and removeable.
I was doing something like this
UBlueprintFactory* Factory = NewObject<UBlueprintFactory>(); UObject* NewAsset = AssetTools.CreateAsset(Name, FPackageName::GetLongPackagePath(PackagePath), UBlueprint::StaticClass(), Factory); UBlueprint* NewBlueprint = Cast<UBlueprint>(NewAsset); AActor* Prefab = GetMutableDefault<AActor>(NewBlueprint->GeneratedClass); UStaticMeshComponent* NewStaticMeshComponent = NewObject<UStaticMeshComponent>(Prefab, TEXT("StaticMesh")); NewStaticMeshComponent->SetStaticMesh(StaticMesh); Prefab->Modify();
But when I open the blueprint, the static mesh isn’t editable at all and I can’t delete the component. Also the static mesh isn’t set.
So now I’m trying to figure out how to add SCS nodes programmatically to the class but it’s not working at all. In code I can see the SCS nodes and everything are created, but when I open the blueprint it’s as if the actor never had any component added at all.