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 absameen · May 08, 2012 at 03:10 PM · editor

Unity Sometimes Ignores Changes

I'm working an a complex editor script that involves saving objects of a custom class type. After changing a property in the custom class and then entering play mode, the variable would sometimes revert to its previous value.

Example: GameObject with component type Animal is in the scene view. Animal has an int property age with the value of 5. User changes the value to 8 from the editor script. User enters play mode and then exits play mode. The variable would sometimes, but not always, revert back to the value of 5.

What could be some possible reasons why this happens and how can I make sure that no data is lost?

Comment
Add comment · Show 1
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 absameen · May 09, 2012 at 04:21 PM 0
Share

$$anonymous$$ost of the base and child classes are ScriptableObjects that are created with CreateInstance. Does Unity have a limit to how much or how often you can save these ScriptableObjects? I am getting a lot of dropped data that occurs randomly but most often when the user enters play mode. I can't seem to figure this one out. This bug is slowing down my development process and I would be grateful for a solution.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rutter · May 08, 2012 at 05:24 PM

Have you been calling `EditorUtility.SetDirty()` on objects you change?

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 absameen · May 08, 2012 at 05:30 PM 0
Share

Actually, I am indeed calling EditorUtility.SetDirty often. This is because I need to refresh OnDrawGizmos. If that is the problem, is there another way to force refresh gizmos without losing data?

avatar image rutter · May 08, 2012 at 06:29 PM 0
Share

It's actually good that you're calling that (sorry, should have been more clear). People tend to overlook it, and then the editor won't be aware that you've made changes.

Off the top of my head, I can't think of what might cause your problem. I'll reply back if I think of anything else.

avatar image
0

Answer by Silicon · May 08, 2012 at 08:44 PM

It depends on how to reference the values in the constructor. For instance if the constructor does not make a call to the property but a call to the field, all instances of that constructor will make the call to the reference field. See Example:

 public class Animal
 {
    private int value;
    public int Value{ get; set;}
    public Animal { value = 0; }
    public int DefaultReturn { return value; }
    public int PropertyReturn {return Value; }
 }

Typically the animal constructor will reference value even if you set it to a different level. I've just seen where if I'm setting a property you want to return the property and not the private variable. It may just be that I'm not as good with objects as I thought but I have seen DefaultReturn send a different value than PropertyReturn.

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 absameen · May 09, 2012 at 04:32 PM 0
Share

I'm not using a custructor with the objects that are being saved. I don't believe this applies.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Editor 'actively refused' attaching debugger 4 Answers

Add same go as a child to multiple gameObjects in hierarchy 0 Answers

Set MinWidth for EditorWindow 1 Answer

Why my Roguelike 2D graphics are naughty in devices? 1 Answer

Left Click Up Event in Editor 4 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