public static GameObject CreateGameObject(Scene scene, HideFlags hideFlags, string name, params Type[] types) { if (!scene.IsValid()) { throw new ArgumentException("Cannot create a GameObject to a null Scene."); } //Internally, this sets the target scene that the scene points to. EditorSceneManager.SetTargetSceneForNewGameObjects(scene); var go = CreateGameObject(name, types); go.hideFlags = hideFlags; EditorSceneManager.ClearTargetSceneForNewGameObjects(); return(go); }