UWORLD::SpawnActor should not be used in Editor

Hi there!

If one calls UWorld::SpawnActor to spawn an (maybe only custom, not verified) actor in the current editor world the object ID will be negative one which is weird.

If that Actor is then deleted and a new one is created again, it will have no root component and cannot be moved around.

GEditor->GetEditorWorldContext().World()->SpawnActor

The correct way of doing this seems to be:

GEditor->AddActor

However I could not find any information on how to properly create Actors in an editor world.

This issue can be resolved by either fixing the SpawnActor behaviour in editor worlds - or by adding a remark to that function so people will know that this can cause issues.

Thank you!

Hey -

Can you explain what you’re attempting to do? From my understanding, it sounds as though you’re attempting to have your actors show in the editor without using the content browser? I feel spawning actors in this way may also cause issues when attempting to package the project. Can you describe what your goal is and/or provide an example of the result you’re getting/expecting.

Hi!

What I am doing is just creating actors in the world from an editor plugin.

This is useful for automagically setting up complex actors and components by creating context sensitive tools. Imagine a tool that spawns a forest with a click of a button.

In this specific case I have a plugin window that must spawn a very specific camera actor in the world to control it (Not in PIE). I was using the SpawnActor method for that before - however that results in the before mentioned problems - AddActor however resolves all the issues.

This has nothing to do with the content browser. All my assets are in the project - so there wont be any issues there. If you want me to I can provide steps for you to recreate the issue.

But basically it is just:

  1. Create a plugin with a button
  2. Create your own actor class with some components
  3. On button click spawn an actor of that class with the UWorld::SpawnActor method
  4. Delete the actor
  5. Click the button again
  6. Inspect the components of the newly spawned actor - they will be missing
  7. Try the same with GEditor->AddActor
  8. It will work fine