Hi I’m trying to place some actor in the map via C++. The code runs in a secondary module associated with a menu item in the editor.
void FLevelStreamModule::OnMenuEntry()
{
AStaticMeshActor* CubeActor = Cast<AStaticMeshActor>(GEditor->AddActor(
GetWorld()->GetCurrentLevel(), AStaticMeshActor::StaticClass(),
FTransform(FVector(0))));
CubeActor->GetStaticMeshComponent()->StaticMesh = LoadObject<UStaticMesh>(nullptr,
TEXT("StaticMesh'/Engine/EditorMeshes/EditorCube.EditorCube'"));
GEditor->EditorUpdateComponents();
CubeActor->GetStaticMeshComponent()->RegisterComponentWithWorld(GetWorld());
GetWorld()->UpdateWorldComponents(true, false);
CubeActor->RerunConstructionScripts();
GLevelEditorModeTools().MapChangeNotify();
}
The actor is is visible in the scene outliner but the mesh is doesn’t appear in the viewport. But when I change any property of the actor from the editor it magically start drawing. How can I notify the editor to start drawing my cube?