Update gameObject's children properties from CustomEditor class
I have a custom button HUD_Button that is the parent of Icon(game object with image component) and Text(game object with text component) and I want to set the Icon's image and Text's string from HUD_Button's inspector. I wrote a custom Editor class for HUD_Button and I try to set them in OnInspectorGUI() like this:
public override void OnInspectorGUI()
{
HUD_Button Ref = target as HUD_Button;
[...] // add custom fields
Image iconComp = Ref.gameObject.GetComponentInChildren<Image>();
if (iconComp != null)
iconComp.sprite = Ref.m_IconSprite;
Text textComp = Ref.gameObject.GetComponentInChildren<Text>();
if (textComp != null)
textComp.text = Ref.m_Description;
}
The problem is that iconComp's material is not being updated in editor, and neither is the textComp's rendered text. However, they get updated if I save the scene. Is there a way to update them without saving the scene? Something like textCom.UpdateRenderedText() and imgCom.UpdateMaterial()
Answer by C-Gabriel · Feb 14, 2016 at 07:05 PM
I had to add EditorUtility.SetDirty(Ref); at the end of the function OnInspectorGUI()
Your answer
Follow this Question
Related Questions
Custom Editor List with child classes 1 Answer
Dynamically sized list of toggles in custom inspector? 0 Answers
Custom Inspector changes not updating target in Edit Mode 1 Answer
Adding space() to BeginHorizontal() causes extra vertical spacing after certain amount. 1 Answer
2D Game Kit Readme inspector 0 Answers