Script not Referencing deleted Text object.

I have a Unity Event setup for starting a dialogue box.

My script then instantiates a dialogue box and get’s references to it’s components to present the data.
When it’s just showing dialogue boxes, it’s fine. It destroys the prefab for the box and I can immediately talk to the NPC again and the script will recreate the box and link up all the references no problem…

Except, if I have dialogue choices for the player. My script is designed to take a new set of dialogue options, call the Unity event and start the process all over again. However when I do this, it loads in these new options OK and I can see them in the inspector, but the references for the Text on the name box and the Text on the dialogue text are missing.


Here’s the specific part of the code I think is causing the problems; I’ve tried a few things like getting the code to wait a second after creating the speech bubble, changing GameObject.Find() to look for tags instead… just can’t seem to get it to work…

public void StartDialouge(DialougeData dd)
    {      
        dialougeTree = new Queue<DialougeStandard.DialougeInfo>();

        CreateBubble();
        aniObject = GameObject.Find("AButtonAni");
        isFinished = false;
        isOptionsOpen = false;

        if (dd.dialougeTree is DialougeChoice)
        {
            DialougeChoice dsChoices = dd.dialougeTree as DialougeChoice;
            options = dsChoices.dialougeChoices;
            availableButtons = new Button[options.Length];
        }

        isDialougeOpen = true;

        nameText = GameObject.FindGameObjectWithTag("NameBox").GetComponent<Text>();
        nameText.text = dd.objectName;
        dialougeText = GameObject.FindGameObjectWithTag("DialougeBox").GetComponent<Text>();
        choiceContainer = GameObject.FindGameObjectWithTag("DialougeButtonContainer");
        choiceButton = GameObject.FindGameObjectWithTag("DialougeOptionButton");
        choiceContainer.SetActive(false);

        EnqueueDialouge(dd.dialougeTree);
        
    }

EDIT: Here’s the code for creating the dialogue box…

public void CreateBubble ()
    {
        bubble = Instantiate(DialougeBubble);
	bubble.transform.SetParent(GameObject.Find("UI").transform);
        RectTransform bubbleRect = bubble.GetComponent<RectTransform>();
        bubbleRect.localScale = new Vector2(0.75f, 0.75f);
        Vector3 actorLocation = player.transform.localPosition;
        bubbleRect.position = new Vector2 (actorLocation.x, actorLocation.y + 5.5f);
    }

Full code is here:
https://pastebin.com/VSWJ7EhH

Try to disable the GameObject instead of destroying it.