- Home /
Problem with Reset and Custom Inspector
I have a MonoBehaviour which contains an array but I didn't like the way the array elements are shown. So I created a custom inspector which does the job, but now the inspector does not update when I reset the MonoBehaviour(right-click->Reset). Everything works fine except for the Reset. When I reset, the values don't get updated until I hit the play button. I tried to use SetDirty in OnInspectorGUI and also SetDirty in the MonoBehaviours Reset method but nothing seems to work.
Without the custom inspector, the reset works just fine.
Answer by DerKleineTomy · Jan 29, 2013 at 05:29 PM
I solved the problem. After I modify my MonoBehaviour, I have to call serializedObject.ApplyModifiedProperties() and serializedObject.Update(). I did it once when trying to solve the problem but I didn't notice a reset because the inspector updates when I leave the modified property. For example I set a value to 1000 and then do the reset, the value won't be updated to the default until I click on another field.
Answer by CodeMasterMike · Jan 28, 2013 at 01:03 PM
To reset your values in the inspector, you need to add the reset function to your script.
function Reset()
{
// Set your data to a default value/s here.
}
You can read more in the reset documentation.
That's what I'm doing. It works as long as I don't use a custom inspector. The reset method gets executed but the custom inspector does not show the new values until I hit the play button (refreshes the inspector I think). I already tried to add SetDirty(this) at the end of the reset method but it doesn't work. SetDirty and Update in OnInspectorGUI didn't work either.
In short: Reset works with default inspector, reset doesn't work with custom inspector.
$$anonymous$$aybe you can post some of the code you have, so that people here might find what is causing this behavior?
I solved the problem. After I modify my $$anonymous$$onoBehaviour, I have to call serializedObject.Apply$$anonymous$$odifiedProperties() and serializedObject.Update(). I did it once when trying to solve the problem but I didn't notice a reset because the inspector updates when I leave the modified property. For example I set a value to 1000 and then do the reset, the value won't be updated to the default until I click on another field.
Your answer
Follow this Question
Related Questions
how to reset only specific properties? 2 Answers
Inspector not refreshing 1 Answer
How to keep certain values on MonoBehaviour Reset method. 1 Answer
My inspector icons keep resetting, can anyone help? 0 Answers
Inspector value resets on prefabs 1 Answer