- Home /
Retrieve default editor field / conditional hide field,
Is there any way to retrieve an editor field from the base editor when creating a custom editor? Ideally I only want to modify one field and am trying to do something like this:
public override void OnInspectorGUI()
{
//recreates default editor
base.OnInspectorGUI();
myField = base.GetField("myFieldName");
// do some stuff with myField
}
I am searching for something like base.GetField
but I haven't been able to find anything like this in the documentation.
As I only want to edit one field, building a complete custom editor seems a hassle and a far from ideal solution.
My end goal is to have a conditional hide field, I am also open to other simple solutions, but am looking for something very simple. Of all the solutions I have seen, most involve adding long scripts to my project. It seems to be something many people are trying to do, I wonder if Unity will consider implementing a ConditionalHideAttribute for editor.
,
If you only need the value, use "target". That is an object being inspected, cast that into your known object type, then access the field from there. Example:
$$anonymous$$yStuff stuff = ($$anonymous$$yStuff)target;
int something = stuff.someField;
Also, an asset called Odin Inspector and Serialized has exactly what you need called [HideIfAttribute] and tons of other things.
Your answer
Follow this Question
Related Questions
SceneView.onSceneGUIDelegate GUI sorting problem 1 Answer
Default toggle style 1 Answer
Custom inspector difficulties creating a Box / Group like widget 1 Answer
EditorGUI.PrefixLabel got truncated 0 Answers
Better Unity Event UI 0 Answers