Error / Issue setting Text using a custom list

Hello Hello,

I am attempting to set some TextMeshPro text using a custom list, but there seems to be an error, issue, or bug that is causing it to not work (unless I misunderstand something)

Here’s a screenshot (I’m currently customizing one of the unity learning games)

I have my custom list which takes 3 variables

  • string dialogue (what we want to say)
  • string speaker (who is saying it)
  • color color (the color we want to assign to those texts)

THE ISSUE


I can set the text directly like this in start or update
tmp_Dialogue.text = "hello| "

And I can even get it to work when I do it in start or update
tmp_Dialogue.text = list_DialogueDict[int_DialogueID].dialogue;

But calling the code through my function causes the dialogue to show BLANK even though the inspector shows what I want

Anyways, I’ll dump my script, and any help is appreciated if I’m missing something

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

/// <summary>
/// <para> UI Text Manager references all of the important UI for buttons, text, and portraits that may show during conversations </para>
/// </summary>

    [System.Serializable]
public class UITextManager : MonoBehaviour
{

   //dialogue text obj & speaker text obj
   [SerializeField] private TextMeshProUGUI tmp_Dialogue, tmp_Speaker;

    //dictionary list of conversational elements to add
   [SerializeField] public List<DialogueDictionary> list_DialogueDict = new List<DialogueDictionary>();
    // the dialogue ID we're on
    private int int_DialogueID;

    private string _testString = "testing...";

    // options

    // a function immediately change and update the dialogue
    public void UpdateDialogue(string _newDialogue, string _newSpeaker, Color _speakerColor) ///THIS FUNCTION DOES NOT PROPERLY SET THE INFORMATION
    {
        // make sure root is enabled
        tmp_Dialogue.text = _newDialogue; /// doing this or hard setting it here breaks the text
        tmp_Dialogue.color = _speakerColor;
        tmp_Speaker.text = _newSpeaker;
        tmp_Speaker.color = _speakerColor;
        print("Just passed: " + list_DialogueDict[int_DialogueID].dialogue); /// BUT THIS DOES PROPERLY PRINT THE INFORMATION
    }

    // a function to add dialogue to a list that needs to be read through
    public void AddDialogueToQueue(string _newDialogue, string _newSpeaker, Color _speakerColor)
    {

    }

    // Start is called before the first frame update
    void Start()
    {
        ///THESE ALL WORK WHEN IN THE START FUNCTION
        //tmp_Dialogue.text = "hello| ";
        //tmp_Dialogue.text = list_DialogueDict[int_DialogueID].dialogue;
        //tmp_Dialogue.text = "hello| " + list_DialogueDict[int_DialogueID].dialogue;


        //tmp_Dialogue.color = list_DialogueDict[int_DialogueID].speakerColor;
        //tmp_Speaker.text = "test| " + list_DialogueDict[int_DialogueID].speaker;
        //tmp_Speaker.color = list_DialogueDict[int_DialogueID].speakerColor;

        /// THIS DOES NOT WORK ANYWHERE
        UpdateDialogue(list_DialogueDict[int_DialogueID].dialogue, list_DialogueDict[int_DialogueID].speaker, list_DialogueDict[int_DialogueID].speakerColor); //ISSUE
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("space")) { int_DialogueID++; UpdateDialogue(list_DialogueDict[int_DialogueID].dialogue, list_DialogueDict[int_DialogueID].speaker, list_DialogueDict[int_DialogueID].speakerColor); }
    }

}//end of UITextManager


// the custom list we'll use toe add dialogue
[System.Serializable]
public class DialogueDictionary
{
    public string dialogue, speaker;
    public Color speakerColor;
    // maybe add an image / sprite to show on each speaker?
    //maybe add font for each situation / speaker?

    public DialogueDictionary(string _newDialogue, string _newSpeaker, Color _speakerColor)
    {
        dialogue = _newDialogue;
        speaker = _newSpeaker;
        speakerColor = _speakerColor;
    }

}//end of dialogue dictionary

Just following up, here are some processes that were confirmed and tested work.

using the function with unique strings

hard setting the individual variables (using the dictionary)

//tmp_Dialogue.text = "hello| ";
//tmp_Dialogue.text = list_DialogueDict[int_DialogueID].dialogue;
//tmp_Dialogue.text = "hello| " + list_DialogueDict[int_DialogueID].dialogue;

I also tried creating private root variables that can be used, but this doesnt seem to work either. It’s a bummer because I am having trouble figuring out a workaround to this

this still doesn’t work

I thought I found a workaround to this.

If I keep a local string, I can see the reference!

string _sample = list_DialogueDict[int_DialogueID].dialogue;
UpdateDialogue(_sample, "sample speaker", Color.cyan);

But this doesn’t work in a scalable way. I tried setting all the local references in the the function to UpdateDialogue but it seems that there is some major issue with this transfer of information. I’m wondering if it has to do with my custom list (confusingly titled) DialogueDictionary

 // a function immediately change and update the dialogue
    public void UpdateDialogue(string _newDialogue, string _newSpeaker, Color _newColor) ///THIS FUNCTION DOES NOT PROPERLY SET THE INFORMATION
    {
        // make sure root is enabled

        //local variables (needed because directly setting causes a glitch with TMPro)
        //string localDialogue = _newDialogue;
        //string localSpeaker = _newSpeaker;
        //Color localColor = _newColor;

        string localDialogue = list_DialogueDict[int_DialogueID].dialogue;
        string localSpeaker = list_DialogueDict[int_DialogueID].speaker;
        Color localColor = list_DialogueDict[int_DialogueID].speakerColor;


        tmp_Dialogue.text = localDialogue; /// doing this or hard setting it here breaks the text
        tmp_Dialogue.color = _newColor;
        tmp_Speaker.text = localSpeaker;
        tmp_Speaker.color = _newColor;
        print("Just passed:" + "\n" + _newDialogue + "\n" + _newSpeaker + "\n" + _newColor); /// BUT THIS DOES PROPERLY PRINT THE INFORMATION
    }

Just following up that I reported this to Unity and it was confirmed as an issue