Double Click doesn't open the dialogue: Solution

So, at the end of this lecture, everything worked as the example, if you had the dialogue editor window open, and changed selections it would update the words/titles to match. The one oddity I noticed, is that if I closed the window, and double clicked a dialogue, it would open the editor, but say ‘No Dialogue Selected.’ I then had to click off and click on it again to get it up update.

I’m not sure if this is because I followed the discussion solution of not using OnEnable - and using OnSelectionChange - or if they both would have had the error, the solution, was to add similar code to OnGUI and modify the selectedDialogue variable if you were selected on one - regardless of whether the editor was open yet or not.

Not sure if there are any long term issues with this - but it appears to work fine:

namespace RPG.Dialogue.Editor
{
    public class DialogueEditor : EditorWindow
    {
        Dialogue selectedDialogue = null;

        [MenuItem("Window/Dialogue Editor")]
        public static void ShowEditorWindow()
        {
            GetWindow(typeof(DialogueEditor), false, "Dialogue Editor");
        }

        [OnOpenAsset(1)]
        public static bool OpenAsset(int instanceID, int line)
        {
            Dialogue dialogueAsset = EditorUtility.InstanceIDToObject(instanceID) as Dialogue;
            if (dialogueAsset != null)
            {
                ShowEditorWindow();
                return true;
            }
            
            return false;
        }

        private void OnSelectionChange()
        {
            Dialogue dialogueAsset = Selection.activeObject as Dialogue;
            if (dialogueAsset != null)
            {
                selectedDialogue = dialogueAsset;
                Repaint();
            }
        }

        private void OnGUI()
        {
            selectedDialogue = Selection.activeObject as Dialogue;
            if (selectedDialogue == null)
            {
                EditorGUILayout.LabelField("No Dialogue Selected.", EditorStyles.boldLabel);
            }
            else
            {
                EditorGUILayout.LabelField(selectedDialogue.name, EditorStyles.boldLabel);
            }
        }
    }
}

I moved:

selectedDialogue = Selection.activeObject as Dialogue;

to OnEnable() instead of inside OnGUI() - as this was clearing the dialogue back to ‘nothing selected’ if you navigated around the project too much ignoring the window

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms