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 Sca · Apr 15, 2014 at 02:48 PM · editorprefabserialization

How to save variables in editor, to use them during play mode

I have an editor tool that instantiates objects (around 1000 of them). I then need to store a list of references to those objects, as well as some properties (variables).

For this, I have a class that stores a reference to the object, and other variables. This class is in a prefab's component. However, If i serialize this, it takes approximately one minute when I click 'apply' to save the prefab. It also takes too much time to load the scene. However, instantiating them in runtime takes ~.2 seconds (on a PC).

Is there a better way to save the values of the list while in the editor, so that I can load them faster?

Thanks in advance

[EDIT]

Some code, as requested:

 [System.Serializable]
 
 public class GraphNode :ScriptableObject
 
 {
         public GameObject tileObject;
         public int movementCost;
         public bool occupied;
         public bool walkable;
 
         public bool IsFree {
                 get{ return !occupied && walkable;}
         }
 
         public bool waterTile;
         public List<GraphNode> connections = new List<GraphNode> ();
 } 
 
   [SerializeField]
         private List<GraphNode> _nodes = new List<GraphNode> ();
 
 
Comment
Add comment · Show 7
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 vexe · Apr 21, 2014 at 08:45 AM 0
Share

Post your related scripts

avatar image Sca · Apr 22, 2014 at 09:00 AM 0
Share

Posting this in case you (vexe) subbed and there are no notifications for updates. I posted the code as you asked.

avatar image vexe · Apr 22, 2014 at 09:13 AM 0
Share

Are you certain that this is what's causing the delay? ... Btw, you know that ScriptableObjects can't live in prefabs right? - why do you need your class to be a SO? can't it be a normal class?

avatar image Sca · Apr 22, 2014 at 09:48 AM 0
Share

That was the reason I didn't post the code initially, because I wanted to know if there was a proper way to keep references to game objects in a list (when I assign them in the editor). If I use ScriptableObject, when I create a list of GraphNode, the references to the tileObject will persist (as far as I know).

avatar image vexe · Apr 22, 2014 at 09:57 AM 0
Share

If you just simply want to keep references to some UnityEngine.Objects in a list, where the values persist, you don't need a SO - use a regular class ins$$anonymous$$d and just make sure it's mocked with System.Serializable like you have written above. Use a SO when you want to have say, a Settings object for your game, create the SO with SO.CreateInstance, and an asset with AssetDatabase(mySo, path); - SOs could solve stickier situations, they play well with polymorphic serialization, etc. But you sound like you don't need all that. SOs have their benefits, but they add extra overhead as well...

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Unity custom editor, values will not serialize 1 Answer

Private list is serialized inside a prefab 0 Answers

SerializedObject data wipe when applying to prefab 0 Answers

What is runtime analogy for Editor's PrefabUtility.SetPropertyModifications? 0 Answers

Editing prefab fields from custom editor that are not automatically serialized 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