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 fred_gds · Nov 14, 2014 at 03:54 PM · editormonodevelopclasscustom-class

Custom classes deleted on build/debug

Hey,

I have a couple of c# scripts with custom classes in them in my scene. Each one of those also has an editor extension. So far it works pretty good. But when I change small things in the code and then build/debug the code in Monodevelop it looses the values I entered previously in the editor.

my script is something like this:

 public class myScript
 {
 
  public int valueA;
  public int[] valuesOfA;
 
  public class myClass
 {
  public int insideClassA;
  public int[] insideClassValuesOfA;
 }
 
 myClass myClassVariable = new myClass();
 } 

so if I assign the values myClassVariable.insideClassA, then they will disappear after the build/debug. But if I assign valueA, which is outside the class it will be saved. I don't quite get why it keeps getting deleted...

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 cregox · Nov 14, 2014 at 04:07 PM 0
Share

where are you assigning values to insideClassA?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by cregox · Nov 14, 2014 at 04:09 PM

You definitely should go for some video tutorials, as there's a lot to learn there.

There are 2 typical ways of losing "variable" values:

  • If you assign values on the editor while playing, they will be lost when you stop playing.

  • And if you have values assigned on the script declaration, they will be overwritten by editor values.

Those are a few points covered on tutorials, I believe.

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 fred_gds · Nov 14, 2014 at 04:34 PM 0
Share

Seriously I don't think I need to watch more video tutorials. I don't mean hit Run inside Unity. I'm well aware that changes in Playtime won't get saved. That's not what I'm talking about. I mean the compilation of $$anonymous$$onodevlop.

As when I usually assign a value inside a custom Inspector (values which are not inside the editor extension script but inside the "base" script) then those values will remain even if I recompile the script, as long as I don't delete that variable inside the script.

So I would expect the same behavior if I use a custom class which as far as I know mostly behaves like a container of different variables.

avatar image cregox · Nov 14, 2014 at 06:25 PM 0
Share

I only mean your question evidently shows basic doubts that is everywhere. When it gets into a video tutorial, it means it's asked a lot. And asking "the internet" repeated questions is usually the worst way to go.

For a few amenities: I took the liberty to move your "answer" as a proper comment to my answer, as it clearly was the intention. Also there's no special name (such as "custom") for classes you create. They're still classes.

Finally, if you think you can't find your answer anywhere, you should ask it in a much more clear way. I, for one, did try to help with what I could understand from your question. Some people here are much better than me for understanding what newbies mean in general, maybe you get lucky if they see your question and find enough will to answer it. Try giving steps to reproduce the problem. Sometimes when you do this, you can find the answer just while preparing the question properly.

We can't assign values to an inner class in the editor / inspector. In my experience, compiling, be it on Unity or $$anonymous$$onodevelop (which I only use for debugging, eventually) never ever "deleted" variable values anywhere. And you didn't answer my very basic question I commented in your question. I find it too hard to understand what you mean, if none of what I mentioned already.

$$anonymous$$aybe you do mean monodevelop debugging, though and I just haven't stumbled into that bug. That process is full of bugs from my brief experience. $$anonymous$$aybe it is something you're doing wrong without realizing... If it is within monodevelop, though, I agree it might be hard to find an answered question there.

avatar image
0

Answer by razcrux · Apr 14, 2016 at 05:10 AM

@fred_gds

The answer you are looking for is you need to add:

 [System.Serializable]

Above class variables if you want the editor to retain them when you run.

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

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Modify inspector 2 Answers

A node in a childnode? 1 Answer

UnityScript auto-format? 0 Answers

How to write a shortcut for MonoDevelop editor? 1 Answer

monodevelop 4.0.1 run with empty 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