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 MasterLG · Aug 29, 2013 at 01:29 PM · editorstate saving

Saving data made using the editor

I've made an editor script that attaches various kinds of data to an object, but when I close the editor and reopen (without changing the script), it doesn't remember the state of any of the assigned data. All of it is public variables.

Data includes:

  • boolean

  • 2D array of Vector3

  • 2D array of game objects

  • integers

  • floats

When I reopen Unity, all of this seems to be forgotten.

How do I make it remember all the things I've done using editor scripts for all of the data?

EDIT: How the editor script works is that it interacts with the GameObject's script in such a way that if the GameObject's Vector3 2D array is null, it goes to the 'creation' side of the menu, otherwise it goes to the 'editor' side of the menu.

Whenever I start Unity, it always ends up on the 'creation' side of the menu, which tells me the array is being forgotten, but I'm not sure.

Comment
Add comment · Show 3
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 Polymo · Aug 29, 2013 at 01:41 PM 0
Share

file -> save project or file -> save scene. And if you're using prefabs a safe way is to 'apply' the changes

avatar image MasterLG · Aug 29, 2013 at 01:58 PM 0
Share

I do save before closing, but I tried specifically using the menu to save and it still 'forgets'.

I will add more details to the post in case I was not specific enough.

avatar image numberkruncher · Aug 29, 2013 at 04:07 PM 0
Share

$$anonymous$$ight be easier to diagnose if you show your editor script and the script which represents the object being edited.

2 Replies

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

Answer by MasterLG · Aug 30, 2013 at 04:41 PM

Apparently you can only save arrays if they're 1 dimensional. Took a bit of math-ing, but I reduced all the 2D arrays into 1D arrays and now things are saving. As far as I can tell.

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 numberkruncher · Aug 30, 2013 at 05:38 PM 0
Share

I usually create wrapper methods for 2D array simulation:

 private int columns = 100;
 private int rows = 100;
 private int[] someArray = new int[columns * rows];

 public int GetItem(int row, int column) {
     return someArray[row * columns + column];
 }
 public void SetItem(int row, int column, int item) {
     someArray[row * columns + column] = item;
 }

 // Then just use like this:
 SetItem(5, 2, GetItem(5, 3));
avatar image
0

Answer by darkForester · Aug 29, 2013 at 02:29 PM

I am not sure if this is the solution to your exact problem, but sometimes you may need to use EditorUtility.SetDirty.

This method tells Unity that the object has changed in some fashion and needs to be serialized.

Also, make sure your script has [System.Serializable] attribute attached and each field should be marked with [SerializeField].

Comment
Add comment · Show 4 · 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 Polymo · Aug 29, 2013 at 03:45 PM 0
Share

you dont need to, if the variables are public and as far as i know monobehaviours are serialized frequently by default. EditorUtility.SetDirty needs to be used if you use an Editor script, which i think he isn't.

avatar image numberkruncher · Aug 29, 2013 at 04:05 PM 1
Share

@ValooFX OP has tagged question as "editor script" and "editor" so I guess that SetDirty is relevant in this case.

avatar image MasterLG · Aug 29, 2013 at 04:08 PM 0
Share

I tried adding the attributes and using SetDirty, but it didn't work.

I applied SetDirty after I finished the 'create' process, so after I set up all the variables and create the objects and stuff.

EDIT: In the original post, I wrote that I'm using editor scripts and it's data created by these that's not saving.

avatar image Polymo · Aug 29, 2013 at 04:24 PM 0
Share

oh, didn't see that.

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

19 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

Related Questions

Set prefab to public variable of another script 1 Answer

Create mesh by defining points 3 Answers

Editor Scripting: Is there a "Timeline" class? 0 Answers

can't dynamically add scripts to gameObjects via Editor 0 Answers

Save game state as it's own scene to edit 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