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
1
Question by Veehmot · Oct 18, 2011 at 01:52 PM · editorserializationeditorwindowpersistence

Creating persistent object in Edit mode

As the documentation for EditorUtility.IsPersistent says:

Returns false if the object lives in the scene. Typically this is a game object or component but it could also be a material that was created from code and not stored in an asset but instead stored in the scene.

That's right, I'm creating a material from code, inside an EditorWindow class. How to make it persist and save to disk?

  • [SerializableField] doesn't work.

  • Setting the variable to public doesn't work.

  • EditorPrefs can't help me, because it's only for value types.

  • Any other option?

To clarify, I want to retain the variable reference upon closing Unity3D and opening the project again, I don't even know if it's possible.

Update

I just followed instructions found here, and created the material on disk using AssetDatabase. Although the materials effectively are stored on Assets, the reference itself is lost, so I have to load them everytime in my EditorWindow. To illustrate this point, I uploaded 2 screenshots:

In this, we can see that the materials are loaded, and IsPersistent returns true for all.

http://i.imgur.com/zStuZ.png

I restart Unity3D, and now the references are gone! But the materials are still in the Assets folder.

http://i.imgur.com/XME88.png

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
2
Best Answer

Answer by Veehmot · Oct 18, 2011 at 04:07 PM

Ah, nevermind. I was needing [SerializableField] on the variables.

I understand a little better how it works: **EditorUtility.IsPersistent** tells me if my objects is going to be erased next time Unity3D restarts, because it isn't stored in disk, it isn't stored anywhere! I can't really make it persistent without creating an asset. I was just creating the Material on the fly, but I never told Unity3D where to save it. So I couldn't expect him to save it automatically in a random position.

Seems like the way to go is to create an asset, be it hidden using HideFlags or not. Afer we create an asset, now Unity3D will be able to save the object in disk. The reference itself will be lost, unless you make the reference public, or put [SerializableField] attribute above the variable.

My mistake was to think that [SerializableField] would work even if I didn't create an asset. I guess it doesn't!

If anyone can tell me if I'm right with this, I would appreciate it.

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Serialization depth limit 7 exceeded 1 Answer

PropertyDrawer and EditorWindow 1 Answer

how to display custom [system.serializable ] class in editor window 3 Answers

EditorWindow: How to Serialize variables after PLay 1 Answer

Why does my Unity Serialization not work? Do i miss something? 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