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()

I had to add EditorUtility.SetDirty(Ref); at the end of the function OnInspectorGUI()