Custom Inspector changes not updating target in Edit Mode
I have a custom inspector for a UI component that I wrote which builds a polygon mesh. My problem is that when I change one of the values in the custom inspector during edit time, the target component doesnt reflect those changes. However when I change one of the public variables on the target script itself the changes are shown immediately. Heres my code:
[CustomEditor(typeof(RegularPolygonGraphic))]
public class RegularPolygonEditor : Editor
{
RegularPolygonGraphic Target;
public override void OnInspectorGUI()
{
if(target != null)
{
Target = target as RegularPolygonGraphic;
}
DrawDefaultInspector();
if(Target.Puncture)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Label("Thickness");
Target.Thickness = EditorGUILayout.Slider(Target.Thickness, 0f, 1f);
Undo.RecordObject(Target, "Set Thickness");
EditorGUILayout.EndHorizontal();
}
}
}
Now when I move the slider in the inspector around, the RegularPolygonGraphic target doesnt reflect those changes. However if I modify any other public in the RegularPolygonGraphic script that isnt set by the custom inspector, it updates correctly. I have the same problem in a lot of other scripts which need a custom inspector so simply making the Thickness variable public on the target component isnt an option. Thanks for your help! EDIT: If it helps, the target script is doing most of the work inside OnPopulateMesh(VertexHelper vh) which is overriding that method from the Graphic class.
Answer by Bunny83 · Mar 21, 2018 at 02:41 AM
You have to call RecordObject before you do any changes to your instance. It registers the current state of the object to the Undo system. So any changes applied to the object afterwards will be saved
Thanks but that doesnt seem to have any effect in this case. Any changes made via the slider are applied as soon as I alter any of the public variables in the target script, but it seems like any values set via the custom inspector wont be applied.
Your answer
Follow this Question
Related Questions
OnPreviewGUI for Canvas and UI Elements 0 Answers
Unity Editor - Group Public GameObjects 0 Answers
How to access a Custom Editor components 1 Answer
Custom Inspector Script Resetting Information 0 Answers
editor script problem, looping 1 Answer