- Home /
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...
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.
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.
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.
Answer by razcrux · Apr 14, 2016 at 05:10 AM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613171515im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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