Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by mmeffeW3 · Jul 30, 2021 at 10:47 AM · unityeditoreditorwindow

Develop an EditorWindow that will not be cleared on assemblies reload (just as the Animator Window)

Hi everyone, as the title states, I'm developing a development tool for the Unity Editor. The main difficulty I've found is that every time the editor reload the assemblies (a change in the code, entering/exiting play mode and so on) the window is cleared. I've managed to reload everything using the EditorWindow.OnProjectChange function, but clearing and restoring the window I'm loosing all the internal states (toggle values, the position and scale of a GraphView I have in the hierarchy). I've noticed that the Unity Animator window (that is similar to the window I'm building) doesn't suffer of this problem... How do I achieve this behaviour in my custom window???

Thanks to all

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Jul 30, 2021 at 11:42 AM

Well is all your internal data serializable? If not, of course the data will be lost on an assembly reload. Note that the EditorWindow class is just a ScriptableObject. It's literally derived from ScriptableObject. When an assembly reload happens, Unity will serialize all UnityEngine.Object derived classes which are restored after the reload. When your window looses information it's because it's not serialized. So the same rules apply to editor windows that apply to runtime scripts concerning hot reloading. See script serialization for more information.


Note that during an assembly reload even private variables are serialized as long as their type is serializable in the first place. Have a look my UVViewer for example. I have several variables that I explicitly do not want to be serialized because they are recreated in OnEnable / OnSelectionChange so I need to mark them as "NonSerialized".


So if you're loosing data it's most likely not serializable.

Comment
Add comment · Show 2 · 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 mmeffeW3 · Jul 30, 2021 at 12:39 PM 0
Share

I may have not expressed the problem correctly... I do know how to serialize data, and I've done it. What I want to obtain is a behaviour like the default Unity windows (Animator, UIBuilder, etc...); if you notice, Unity default windows, unlike EditorWindow and derived classes, during assemblies reload, do not have frames with the window emptied and I imagine is due to the fact that the window is not being reloaded and I wish to replicate that behaviour (if possible :) )

avatar image Bunny83 mmeffeW3 · Jul 30, 2021 at 06:54 PM 0
Share

unlike EditorWindow and derived classes, during assemblies reload, do not have frames with the window emptied

Sorry but I don't get what you mean. My own editor window, specifically the UVViewer I mentioned does not have a single frame empty when an assembly reload happens.


Every window will be serialized, destroyed and recreated when an assembly reload happens. The whole managed Mono environment is shutdown and restarted when this happens. If the state of your window is serialized properly you should not notice any issues. Keep in $$anonymous$$d that static variables are not serialized. This is mentioned in the very last sentence in the script serialization documentation I mentioned in my answer. The Animation window is also just a managed window and is in no way different then any other EditorWindow. So if your window has issues, it's because of your code or that you loose state during the reload because it wasn't serialized properly.


Feel free to try my UVViewer. Just put the file in an editor folder and open the window from the Tools menu. Now just select any object in the scene to view the UV map of that object. If you now edit any of your scripts in the background and switch back to Unity, you will notice the window will stay as it is.


We can't really help you any further with your specific problem since that depends on your specific code. Maybe you use data structures in your editor window that are not serializable?

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

129 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 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

Error: Unable to load the icon: 'CustomEditorWindow'. (Custom Scene View) 1 Answer

Losing serialized data after play button pressed. 0 Answers

how to stop reorderable list from passing Event value to the new element 1 Answer

Changed data through EditorWindow isn't persistent. 1 Answer

Converting from EditorWindow to runnable window 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