So any time you search for this, you get told
[SerializeField]
private int myVar;
Problem: values will be serialized to disk.
Or the other way around:
[System.NonSerialized]
public int myVar;
Problem: now you can’t see it in the editor
Or you could try:
#if UNITY_EDITOR
public
#endif
int myVar;
Problem: lol
Or you could put the inspector into debug mode…
Problem: you lose custom inspectors, headers, spacing, etc it’s a tiny, fiddly button and the values are readonly.
Or you could write a custom inspector:
Problem: lol you’d spend longer writing custom inspectors than getting on with code. this isn’t remotely viable. Just, no.
So then I did try patching the editor.dll as there’s a flag which determines whether a field has the serializable property, but that didn’t work too well. (You’d have to go deeper into the serialization .dll and I think at that point you might as well just be making private vars public).
Problem: didn’t work, or just showed everything
So the solution I’ve settled on for now, is to jump into the UnityEngineCore.dll and unseal the UnityEngine.SerializeField attribute.
E.g. extend it as shown:
#if UNITY_EDITOR
public class SemiSerializableAttribute : UnityEngine.SerializeField {
public SemiSerializableAttribute(){}
}
#else
public class SemiSerializableAttribute : System.Attribute {
public SemiSerializableAttribute(){}
}
#endif
Problem: nextlevel janky, I wouldn’t know where to start.
There must be a better way to have a private var, that the inspector can edit at runtime, since there’s nothing at all in the language spec stopping it.
E.g. not publicly exposed (giggity), but orders of magnitude quicker to debug than firing up the debugger, trapping and tweaking values.
Any ideas?
Cheers.


