Download

Placing a StaticMeshActor into the editor scene from plugin?

I have to dynamically add new actors of type AStaticMeshActor to the currently loaded scene in the editor, but I am having some problems doing this.

I followed some stuff I found on spawning actors, and on getting the editor world, but it isn’t working. I am doing basically this:



FVector position;
FRotator rotation;
AStaticMeshActor* newActor = GEditor->EditorWorld->SpawnActor<AStaticMeshActor>(position, rotation);
newActor->GetStaticMeshComponent()->SetStaticMesh(existingMesh);


But the call to SpawnActor() is crashing.

Can anyone help me out?

Thanks!

It seems like the CurrentLevel pointer in the world is invalid, which I don’t understand. I mean this is the EditorWorld and I obviously have a level loaded.

EDIT: No actually GEditor->EditorWorld is returning a null :frowning:

Ok so how do I get a darned pointer to the current world being edited in the editor?

To follow up here for future reference, apparently what you need is:

GEditor->GetEditorWorldContext().World()

Thx John, was lookin for it too :slight_smile: