After some debugging I could understand how to make it.
Warning! This is very bad voodoo, dont do it until you will be sure you need it.
So, add two dependencies into Build.cs
PrivateDependencyModuleNames.AddRange(new string[]
{ " "UnrealEd", "Kismet", "SubobjectEditor" });
Then call next code in some function called by blueprint editor. PreInitializeComponents should be fine.
USkeletalMeshComponent* SkeletalMeshComponent =
NewObject<USkeletalMeshComponent>(
this,
USkeletalMeshComponent::StaticClass());
// We register the components and attach them to the editor
// We are adding at runtime so its necessary to manually register to the engine.
SkeletalMeshComponent->AttachToComponent(
GetRootComponent(),
FAttachmentTransformRules::KeepRelativeTransform);
// Manually called because the component won't appear in the list without this
// call.
Actor->AddInstanceComponent(SkeletalMeshComponent);
Dont register component, this have no point inside editor.
Then, the real magic have begin.
FBlueprintEditorModule& BlueprintEditorModule = FModuleManager::LoadModuleChecked<
FBlueprintEditorModule>("Kismet");
IBlueprintEditor& EditorRef = BlueprintEditorModule.GetBlueprintEditors()[0].Get();
FBlueprintEditor& DerivedRef = static_cast<FBlueprintEditor&>(EditorRef);
SSubobjectEditor* SS = DerivedRef.GetSubobjectEditor().Get();
AMyActor* Context = Cast<AMyActor>(SS->GetObjectContext());// get context
USkeletalMeshComponent* SkeletalMeshComponent =
NewObject<USkeletalMeshComponent>(
Context ,
USkeletalMeshComponent::StaticClass());
SkeletalMeshComponent->AttachToComponent(
Context->GetRootComponent(),
FAttachmentTransformRules::KeepRelativeTransform);
Context ->AddInstanceComponent(SkeletalMeshComponent);
SS->UpdateTree();//update component tab
If you do everything right, runtime created components appears in blueprint viewport AND blueprint component tab.