GEditor->AddActor crash

1)Create a fresh plugin with buttons

2)change PluginButtonClicked() to

	UWorld* const World = GEditor->GetEditorWorldContext().World();
	try {
		UStaticMeshComponent* newmesh = Cast<UStaticMeshComponent>(GEditor->AddActor(World->GetCurrentLevel(), UStaticMeshComponent::StaticClass(), FTransform(FVector(0))));
	}catch (...) {}

The engine crashes. Anyone know a workaround?

First of all you cant add a UStaticMeshComponent to the level because GEditor->AddActor want a AActor type and UStaticMeshComponent is a UMeshComponent and this is the issue that cause the editor crash

so insted of trying to spawn a UStaticMeshComponent you should spawn a AStaticMeshActor this way:

//dont forget to add the include file for the Actortype
#include "Engine/StaticMeshActor.h"
//inside PluginButtonClicked()
UWorld* const World = GEditor->GetEditorWorldContext().World();
AStaticMeshActor* newmesh = Cast<AStaticMeshActor>(GEditor->AddActor(World->GetCurrentLevel(),AStaticMeshActor::StaticClass(), FTransform(FVector(0))));

and the you can add the component to the actor newmesh->AddComponent(/*components parementers here*/)

Hope this helps,

oh I see, that makes perfect sense, thanks.

Thanks for answer. I had same problem about my basecharacterclass . I fix thanks to you