- Home /
How do I render objects in a PreviewScene?
I have used EditorSceneManager.NewPreviewScene to create a temporary scene that i render to the Scene view camera, but now I need to add a GameObject to it. In code i can see that the object is in the scene but it still doesn't render in the scene view camera. What am I missing?
The documentation seem to be lacking when it comes to preview scenes and i can't figure it out.
if (GUILayout.Button("Open preview scene"))
{
previewScene = EditorSceneManager.NewPreviewScene();
if (SceneView.lastActiveSceneView.camera != null)
SceneView.lastActiveSceneView.camera.scene = previewScene;
var go = Instantiate(prefab);
EditorSceneManager.MoveGameObjectToScene(go, previewScene);
var a = previewScene.GetRootGameObjects()[0];
Debug.Log(a.name);
}
The last row of the code prints the correct name of the prefab so it seems like it's correctly moved in to the scene
Answer by velenrendlich · Jan 07, 2020 at 02:55 PM
PrefabUtility.LoadPrefabContentsIntoPreviewScene seems to work for me.
Your answer
Follow this Question
Related Questions
Editor: Drawing outside the own window 0 Answers
Multiple editor windows combined 0 Answers
Prefabs are instantiated in editor but not in executable 2 Answers
Reflection on class variable values null on editor startup 0 Answers
Fastest way to instantiate and move multiple game objects in the editor 3 Answers