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 $$anonymous$$ · Dec 05, 2012 at 10:07 AM · editor-scriptingcompile

Inspector Scripts stops working after each compile

I have a custom inspector script for a spline, it stores points in a list. It fully works, but when unity recompiles any script in the project, all the data seems to get lost and the script doesn't work anymore (the contents in the inspector are gone) untill I reset the script in unity.

What can cause this problem? And how do I solve it? Because its very useless now, with each compile of a script I have to reset the spline script and redo all the work.

Update:

When saved in a prefab the data is there, even after a recompile. When I reload the scene or press play, the data is back visible in the inspector.

Is there maybe a way to catch a recompile event and refresh the inspector or something like that, or a manual deserialize?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by SirIntruder · Sep 01, 2013 at 12:59 PM

You should stay away from saving permanent data into custom inspector classes. Save them in the inspected class instead. I'm not 100% sure on the life cycle of instances of Editor-derived scripts, but it is entirely possible that they all get deleted and recreated on recompile, together with anything that was statically initialized (all static classes' constructors are re-called on recompile).

For your second question - I don't know for a documented way of intercepting recompile events, but you could use the fact that static constructors are called on recompile. The catch is that most of the Unity functionality apparently doesn't work when called from static class constructors. It probably has something to do with the order of initialization of various codes on program-load. You can circumvent that by just setting a flag in static constructor.

 public static class RecompileListener
 {
     private static bool loaded;
 
     // This should ban setting Loaded to false outside the class.
     public static bool Loaded 
     { 
         get { return loaded; }
         set { if (value != false) loaded = value; }
     }
 
     static RecompileListener()
     {
         // This is called on code recompile
         loaded = false;
     }
 }
 
 //some Unity class method
 if (!RecompileListener.Loaded)
 {
     RefereshStuff;
     RecompileListener.Loaded = true;
 }
 
 
Comment
Add comment · 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
0

Answer by Psymon · Dec 05, 2012 at 11:22 AM

If the data stored in your spline is not serializable, the inspector will not save the contents.

You may have to define other classes in order to make your spline serializable.

For example an array of an array is not serializable, you have to make another class in order to make it serializable :

 [System.Serializable]
 public class AssetArray {
  public string[] array;
 }
 
 public class myClass {
  public AssetArray[] listAssets;
 }


If your prefab is saved as a file text you can check if the data is stored by opening it with a text editor.

Comment
Add comment · Show 12 · 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 $$anonymous$$ · Dec 05, 2012 at 11:25 AM 0
Share

The data is stored. When I close the scene and reopen it, the spline still exists. But when it recompiles a script the spline disappears. And when I close Unity and re-open it, it is still there.

avatar image Psymon · Dec 05, 2012 at 12:28 PM 0
Share

This is exactly the same problem i encountered in my example. The inspector still showed me the content but when i compiled it disappears. Can you check the prefab as a text file to be exactly sure the data is stored in the file ?

avatar image $$anonymous$$ · Dec 05, 2012 at 12:35 PM 0
Share

Don't know what you mean by check as a text file. But when I open it with notepad I get: x (  3.5.0f5 þÿÿÿ é Prefab Base ÿÿÿÿ  €  UInt32 m_ObjectHideFlags     Prefab$$anonymous$$odification m_$$anonymous$$odification ÿÿÿÿ  €  PPtr m_TransformParent      SInt32 m_FileID     SInt32 m_PathID     vector m_$$anonymous$$odifications ÿÿÿÿ  €  Array Array ÿÿÿÿ   €  SInt32 size     Property$$anonymous$$odification data ÿÿÿÿ  €  PPtr target     SInt32 m_FileID    SInt32 m_PathID    string propertyPath ÿÿÿÿ  €  Array Array ÿÿÿÿ   @  SInt32 size     char data     string value ÿÿÿÿ  €  Array Array ÿÿÿÿ   @  SInt32 size     char data     PPtr objectReference      SInt32 m_FileID     SInt32 m_PathID     vector m_RemovedComponents ÿÿÿÿ    Array Array ÿÿÿÿ     SInt32 size     PPtr data      SInt32 m_FileID     SInt32 m_PathID     PPtr m_ParentPrefab      SInt32 m_FileID     SInt32 m_PathID    PPtr m_RootGameObject  !    SInt32 m_FileID  "   SInt32 m_PathID  #   bool m_IsPrefabParent  $   bool m_IsExploded  %  @   g÷ ( é é 

avatar image Psymon · Dec 05, 2012 at 12:52 PM 0
Share

On the toolbar : Edit/Project Settings/Editor check if the asset serialization is set as Force Text like this :

http://uppix.net/f/0/3/3a69a998b3e25506a4f494c958974.jpg

Then when you open the prefab with Notepad try to find your script Spline in the text(there must be a line written $$anonymous$$onoBehaviour: ). When you find your script check if your variables are written.

For example :

$$anonymous$$onoBehaviour:

playAnimOnStart: 1

$$anonymous$$y monobehaviour has a variable named playAnimOnStart set to 1 in this prefab.

avatar image $$anonymous$$ · Dec 05, 2012 at 12:56 PM 0
Share

Done that, and the data is in the text file. m_Name: _name: Test _controlPoints: - _position: {x: .523728788, y: .0570619702, z: .113889799} ...

Show more comments

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

10 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

Related Questions

Material.mainTexture not working outside of runtime? 1 Answer

How do I get an array of names of all the sprites in a project, with an editor script? 2 Answers

Unity API for checking if an object was modified 3 Answers

How to minimize the main editor Window by script 1 Answer

Why would editor script be slow on first compilation? 0 Answers


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