Hi,
I’m experimenting a bit with custom editor, and so far, everything is almost fine.
The “almost” part is some problem with my latest script, a component supposed to update a couple GUIText (in other GameObjects), in fact, I want this script to be a centralized way of editing several texts at a time.
The thing is that whenever I update the string field of my CustomEditor, it does update the string field of the GUIText, but the text itself, as I see it in my scene, doesn’t get refreshed. To be fair, sometimes it does refresh the GUIText… But in a messed up way…
It will refresh afterward, whenever I move the GUIText, or enable/disable it, but it’s kinda… Messy, and I wish I could solve this issue.
I guess it might be a bit hard to explain / understand, but images are worth a thousand words, so here it is :
!(http://i.imgur.com/fhG6BH3.png “Help”)
Sometimes, instead of a messed up text, it just doesn’t update at all.
Notes :
- I do call Undo.RecordObject to save my object
- I don’t call EditorUtility.SetDirty, it apparently shouldn’t be used anymore (since Unity 5.3, I’m using 5.3.6p5 by the way), and although it does update the scene view / game view properly, it doesn’t save my serialized attributes properly (they are reseted when I reload the scene / reopen the project)
- Although I don’t think it’s related to the issue, the string exposed in the editor is actually part of a non-serialized Dictionary. The key / value are serialized by being stored in 2 Lists, “key” and “value” as suggested by this page of the documentation : Unity - Scripting API: ISerializationCallbackReceiver.OnBeforeSerialize
- If I add “base.InspectorGUI()” at the beginning of my custom InspectorGUI code, those lists become available in the editor (instead of the Dictionary values, wich I do not want). Updating the “value” list does what I want, meaning that the original InspectorGUI has lines of code doing what I want to, I just need to figure wich lines… But I can’t see the code of the original Editor class, can I?
So, basically, what I need is probably some generic (not GUIText related) line of code that updates the scene I guess.
This is a simplified version of my code :
serializedObject.Update();
MyCustomComponent myScript = target as MyCustomComponent;
SerializedProperty toa = serializedObject.FindProperty("textObjectArray");
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(toa, true);
EditorGUILayout.Space();
EditorGUILayout.LabelField("ROTATION Instruction Text");
//Saves the value to a serialized attribute of MyCustomComponent and changes the text attribute of all Texts stored within the textobjectArray
myScript.setInstructionText(EditorGUILayout.TextArea(myScript.getInstructionText, GUILayout.MaxHeight(30)));
if (EditorGUI.EndChangeCheck())
{
serializedObject.ApplyModifiedProperties();
}
if (GUI.changed)
{
Undo.RecordObject(myScript, "Saving Instruction Dispatcher of "+ myScript.gameObject.name);
}
I believe I’m missing an instruction to refresh the scene based on the changes I’ve made.
If anyone has a clue on what I’m missing, I’d follow any lead, thanks