- Home /
Custom inspector debug display or prevent SerializeField editing
Is there anyway to change how a custom inspector displays when in debug mode? Or to prevent a field tagged SerializeField from being editable when the inspectors in debug mode? Or another solution to the following problem?
I have a component with a custom inspector that allows changes to several properties of the component. An example property looks like this
[SerializeField] private bool internalMaintainViewportFieldofView = false; public bool MaintainViewportFieldofView { get { return internalMaintainViewportFieldofView; } set { bool changed = internalMaintainViewportFieldofView != value; if (changed) { if (Transitioning) throw new TransitionInProgressException("Can't change properties while a transition is inprogress");
internalMaintainViewportFieldofView = value;
// A bunch of other things that need doing
}
}
}
This all works fine and my custom inspector works and correctly uses the public property.
The problem, is that when the inspector is in debug mode, the private variable is visible (fine) and editable (not fine).
Removing the SerializeField attribute stops it being editable but then the value doesn't get serialized, so that's no solution.
Answer by Eagle32 · Sep 07, 2010 at 06:25 AM
Well I found an acceptable solution. Adding the [HideInInspector] attribute along with the [SerializeField] attribute gets me an acceptable result. That being that the private variable is saved and not visible when in the debug inspector.
A better solution would have it visible but not editable.
The optimum solution would be a custom gui for the debug inspector.
Can anyone provide a better solution?
If you have a custom inspector you could use EditorGUILayout.LabelField to display the value of your read-only property.
http://unity3d.com/support/documentation/ScriptReference/EditorGUILayout.LabelField.html
Doing that would not solve this problem. In the debug inspector it would still be visible and editable or invisible. I too think you should be able to view but not edit in the debug inspector.