- Home /
HowTo: Editor only properties
Here's my problem :
I added several times the same component to a GameObject and set different properties to each component. I made an editor class that draws handles to help me configure the components.
But, I want to see only the handles of a restricted set of components. To do so, I added to the component script :
#if UNITY_EDITOR
public bool IsEditable = false
#endif
In my editor script, I draw the handles only if IsEditable == true
So I can set in the inspector which component's handle are drawn, until here, everything is fine.
Then, I tried a standalone build, which crashed at launch. I looked up the log and found :
A script behaviour has a different serialization layout when loading. (Read 36 bytes but expected 56 bytes)
Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
I suspect that my compiler condition is not correct.
One way is to have the IsEditable only serialized in editor, and then have assets cleaned. But, that's really ugly.
An other way would be to add a kind of metadata to my component that will be only used in my editor.
Have someone found a workaround or a clean way to "attach" data to a component script ?
Thanks in advance, any hints would be appreciated.
Answer by fredpointzero · Sep 01, 2011 at 11:57 AM
I found the answer : use the attribute NonSerialized and pay attention to which fields are for the editor !