Unity Errors: Can't rename to empty name & IndexOutOfRangeException

I’m following along with a Unity 2D RPG course on Udemy and I’m having a couple issues. The errors I’m getting are:
IndexOutOfRangeException: Index was outside the bounds of the array. DialogManager.Update () (at Assets/Scripts/DialogManager.cs:36) & Can’t rename to empty name UnityEditor.ProjectWindowUtil:CreateScriptAssetFromTemplateFile(String, String).

The script it appears to be hung up on is my Dialog Manager script which is this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DialogManager : MonoBehaviour
{

    public Text dialogText;
    public Text nameText;
    public GameObject dialogBox;
    public GameObject nameBox;

    public string[] dialogLines;

    public int currentLine;

    public static DialogManager instance;


    // Start is called before the first frame update
    void Start()
    {
        instance = this;

        //dialogText.text = dialogLines[currentLine];
    }

    // Update is called once per frame
    void Update()
    {
        if(dialogBox.activeInHierarchy)
        {
            if(Input.GetButtonUp("Fire1"))
            {
                currentLine++;

                if(currentLine >= dialogLines.Length)
                {
                    dialogBox.SetActive(false);
                } else 
                {
                    dialogText.text = dialogLines[currentLine];
                }

            }
        }
    }

    public void ShowDialog(string[] newLines)
    {
        dialogLines = newLines;

        currentLine = 0;

        dialogText.text = dialogLines[0];
        dialogBox.SetActive(true);
    }
}

Basically what happens is when I approach an NPC I should get a dialog box and response. My trigger is set in the inspector on the Collider but nothing happens and my canActivate trigger never activates when I walk inside the area. Visual Studio shows no errors. But it appears the hang up is on line 36 with currentLine++

I’m almost positive all my spelling and capitalization is correct so I’m not really sure what else to do. There’s also a Dialog Activator script but I don’t think that’s causing any issues. Just in case I’ve added that as well…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DialogActivator : MonoBehaviour
{

    public string[] lines;
   
    private bool canActivate;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        if(canActivate && Input.GetButtonDown("Fire1") && !DialogManager.instance.dialogBox.activeInHierarchy)
        {
            DialogManager.instance.ShowDialog(lines);
        }
    }

    private void OnTriggerEnter2d(Collider2D other)
    {
        if(other.tag == "Player")
        {
            canActivate = true;
        }
    }

    private void OnTriggerExit2d(Collider2D other)
    {
        if(other.tag == "Player")
        {
            canActivate = false;
        }
    }
}

currentLine++ is not the source of your error. Are you sure your script is saved and has recompiled?
Actually, line 36 is a {, which also can’t be an index out of range error. What would give you the error is if you try to access a collection (like the dialogLines array) and you wanted to access index 10, when it only had up to index 9 for example.

The other error seems to suggest you are trying to rename something to an empty name. But I’m only guessing by the error context. It also doesn’t have to be you, it could be an editor script trying to do that.

Thanks for the help Brathnann. My issue was in the Dialog Activator script. I had 2d instead of 2D for the OnTriggerEnter2D.

Sometimes it’s the little things :slight_smile: Glad you found your error.