Having a really weird error called ArgumentException

Some reasons on the Dialogue editor, it’s creating infinite serial codes and it’s making an error.
Can anyone help me to fix this issue? I downloaded scripts from the Github and try to check whether there is a typing mistakes but I couldn’t find anything. Thanks.

That’s one I haven’t seen before. At first blush it feels like a Unity internal error, but it is directly referencing the DialogueEditor.

Paste in your DialogueEditor.cs. Before pasting it in, go to line 119 in the code (that’s where the stack trace points) and add //Line 119. Do the same with line 85 //Line 85. This will help me since our forums dont’ include line numbers in code.
Be sure to paste the text of the script, not a screenshot.

Hi Brian,

Thank you for your reply!
This is a DialogueEditor Code that you asked for.

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.Graphs;
using UnityEditor.MPE;
using UnityEngine;

namespace RPG.Dialogue.Editor
{
    public class DialogueEditor : EditorWindow
    {
        private Dialogue selectedDialogue = null;
        [NonSerialized] private GUIStyle nodeStyle;
        [NonSerialized] private DialogueNode draggingNode = null;
        [NonSerialized] private Vector2 draggingOffset;
        [NonSerialized] private DialogueNode creatingNode = null;
        
        //show editor from window panel
        [MenuItem("Window/Dialogue Editor")]
        public static void ShowEditorWindow()
        {
            //utility true/false -> using once(true) or not(false)
            GetWindow(typeof(DialogueEditor), false, "Dialogue Editor");
        }
        
        //double click on the project folder, interaction happens
        [OnOpenAsset(1)]
        public static bool OpenDialogue(int instanceID, int line)
        {
            //get ID and try to find the object. if there is no object, return null
            Dialogue dialogue = EditorUtility.InstanceIDToObject(instanceID) as Dialogue;
            if (dialogue != null)
            {
                //open dialogue editor
                ShowEditorWindow();
                return true;
            }
            return false;
        }

        //similar as a start function but OnEnable function occurs every object active.
        private void OnEnable()
        {
            Selection.selectionChanged += OnSelectionChanged;

            nodeStyle = new GUIStyle();
            nodeStyle.normal.background = EditorGUIUtility.Load("node0") as Texture2D;
            nodeStyle.normal.textColor = Color.white;
            nodeStyle.padding = new RectOffset(20, 20, 20, 20);
            nodeStyle.border = new RectOffset(12, 12, 12, 12);
        }

        //void name can be change
        //give an information to the that is selected on the opened Dialogue Editor
        private void OnSelectionChanged()
        {
            Dialogue newDialogue = Selection.activeObject as Dialogue;
            if (newDialogue != null)
            {
                selectedDialogue = newDialogue;
                Repaint();
            }
        }

        //text & ID showing on the editor (text info can change on the editor) 
        private void OnGUI()
        {
            if (selectedDialogue == null)
            {
                EditorGUILayout.LabelField("No dialogue selected");
            }

            else
            {
                ProcessEvents();
                foreach (DialogueNode _node in selectedDialogue.GetAllNodes())
                {
                    DrawConnections(_node);
                }
                foreach (DialogueNode _node in selectedDialogue.GetAllNodes())
                {
                    DrawNode(_node);
                }
                if(creatingNode != null)
                {
                    Undo.RecordObject(selectedDialogue, "Added Dialogue Node");
                    selectedDialogue.CreateNode(creatingNode);
                    creatingNode = null;
                }
            }
        }

        //drawing dialogue panel bezier(line), 노드 선 그리기
        private void DrawConnections(DialogueNode _node)
        {
            Vector3 startPosition = new Vector2(_node.rect.xMax, _node.rect.center.y);
            
            foreach (DialogueNode childNode in selectedDialogue.GetAllChildren(_node))
            {
                Vector3 endPosition = new Vector2(childNode.rect.xMin, childNode.rect.center.y);
                Vector3 controlPointOffset = endPosition - startPosition;
                controlPointOffset.y = 0;
                controlPointOffset.x *= 0.8f;
                Handles.DrawBezier(
                    startPosition, endPosition, 
                    startPosition + controlPointOffset, 
                    endPosition - controlPointOffset, 
                    Color.white, null, 4f);
            }
        }

        private void DrawNode(DialogueNode _node)
        {

            //rectangle grouping size
            GUILayout.BeginArea(_node.rect, nodeStyle);
            EditorGUI.BeginChangeCheck();
                
            string newText = EditorGUILayout.TextField(_node.text);
                
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(selectedDialogue, "Update Dialogue Text");
                _node.text = newText;
            }

            if(GUILayout.Button("+"));
            {
                creatingNode = _node;
            }

            GUILayout.EndArea(); //end rectangle grouping size
        }

        private void ProcessEvents()
        {
            //dragging
            if (Event.current.type == EventType.MouseDown && draggingNode == null)
            {
                draggingNode = GetNodeAtPoint(Event.current.mousePosition);
                if (draggingNode != null)
                {
                    draggingOffset = draggingNode.rect.position - Event.current.mousePosition;
                }
            }
            
            else if (Event.current.type == EventType.MouseDrag && draggingNode != null)
            {
                //track the position
                Undo.RecordObject(selectedDialogue, "Move Dialogue Node");
                draggingNode.rect.position = Event.current.mousePosition + draggingOffset;
                GUI.changed = true;
            }
            
            //stop dragging
            else if (Event.current.type == EventType.MouseUp && draggingNode != null)
            {
                draggingNode = null;
            }
        }

        private DialogueNode GetNodeAtPoint(Vector2 _point)
        {
            DialogueNode foundNode = null;
            foreach (DialogueNode _node in selectedDialogue.GetAllNodes())
            {
                if (_node.rect.Contains(_point))
                {
                    foundNode = _node;
                }
            }
            return foundNode;
        }
    }
}


I’m not seeing anything specific here that would be causing this.

The only reference I could find to an ArgumentException related to BeginArea involved changing the size of the layout between the Layout phase and the Repaint phase. As this is a TextField, it seems unlikely that anything would be changing.

The only thing I can think of is if for some reason, it’s not liking setting _node.text within the layout phase… Here’s something to try (this is off the cuff, so no guarantees here)

Remove the EditorGUI.BeginChangeCheck() and the if EditorGUI.EndchangeCheck()) block.
At the END of the event after GUILayout.EndArea(), add this:

if(Event.current.type = EventType.Repaint() && newText!=_node.text))
{
    Undo.RecordObject(selectedDialogue, "Update Dialogue Text");
    _node.text = newText;
}

Oh, I just found the issue. It was my mistake, and it’s such a dumb one that I could make, haha. :joy:Thank you for your help, Brian.

My code :

if(GUILayout.Button("+"));
{
    creatingNode = _node;
}

The corrected code:

if (GUILayout.Button("+"))
{
    creatingNode = _node;
}

LOL, I totally missed that ;
Many times errors are quite literally a ; here, or a ! there (or lack thereof).
Glad you got that up and running!

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

Privacy & Terms