Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by TreyH · Mar 22, 2017 at 02:58 PM · sceneeditorwindoweditorutility

Objects created in EditorWindow do not persist after reloading project

Hello, I've looked through a few similar questions and didn't find quite what I was looking for. There were a few questions whose solutions involved serializable fields and scriptable objects, but this felt a bit different.

Suppose I have a simple editor window that creates an object. The object will appear in the scene hierarchy correctly, but will not persist through closing / reloading the project scene.

If I manually change the object (rename, change parent, etc) using the Scene Editor itself, then the object will persist. I'm assuming there is a trivial solution for this, but have not had much time to investigate.

Thanks:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 using System.Collections.Generic;
 
 public class CreateObjectWindow : EditorWindow
 {
     // Keep track of what we've made
     private static List<GameObject> createdObjects;
 
     [MenuItem ("Window/CreateObject")]
     public static void OpenCreateObjectWindow ()
     {
         // Make the window
         var window = EditorWindow.GetWindow (typeof(CreateObjectWindow));
 
         // Initialize the list
         createdObjects = new List<GameObject> ();
     }
 
     void OnGUI ()
     {
         // Simple single button
         if ( GUILayout.Button ("Create Object!") )
         {
             // Make some empty object
             GameObject go = new GameObject ("made in editor!");
             createdObjects.Add (go);
 
             // Check if this is persistent (which it will not be)
             bool persists = EditorUtility.IsPersistent (go);
             Debug.LogFormat ("New object will persist? {0}", persists);
         }
     }
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadyProductions · Mar 22, 2017 at 03:05 PM 2
Share

https://docs.unity3d.com/ScriptReference/EditorApplication.SaveScene.html

avatar image BennyKokMusic · Mar 22, 2017 at 03:11 PM 2
Share

Have u tried creating the game object using Instantiate(...); ?

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by ShadyProductions · Mar 22, 2017 at 03:05 PM

https://docs.unity3d.com/ScriptReference/EditorApplication.SaveScene.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TreyH · Mar 22, 2017 at 03:17 PM 2
Share

obsolete reference but it did point me in the right direction for a solution:

 // Get the current scene we're using
 var currentScene = UnityEditor.Scene$$anonymous$$anagement.EditorScene$$anonymous$$anager.GetActiveScene ();
 
 // $$anonymous$$ake it dirty (or save will ignore it) and then force a save call
 UnityEditor.Scene$$anonymous$$anagement.EditorScene$$anonymous$$anager.$$anonymous$$arkSceneDirty (currentScene);
 UnityEditor.Scene$$anonymous$$anagement.EditorScene$$anonymous$$anager.SaveScene (currentScene);

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

71 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a callback for when a scene gets unloaded in the Editor? 1 Answer

Draw Rect in Scene View from EditorWindow 0 Answers

Move objects in scene view before running the game 0 Answers

Browse where all scripts are relative to gameobject reference 0 Answers

Open scene and load prefab 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges