Search Unity

Question Missing Something about Using TMPro in a Script-Populated List

Discussion in 'UGUI & TextMesh Pro' started by Vaeryx, Feb 6, 2023.

  1. Vaeryx

    Vaeryx

    Joined:
    Jan 7, 2020
    Posts:
    7
    Unity Version: 2021.3.18f
    Other Assets: TMPro

    Hey folks,

    I'm working on prototyping a detective-style game, and as part of it, I'm wanting to make an evidence presentation system, like Ace Attorney. Currently, I'm making the UI for it, based on this video series.

    Problem is, that video is five years old and doesn't use TMPro, which is now the default in Unity. I didn't think that would be an issue, but boy was I wrong. I couldn't the "myText" variable to accept the button's default text, because the button's default text is a TMPro asset. So, I had to change up the code from the video, in the hopes of getting it to work.

    I'm as close as I've gotten to functional, but I feel I've hit a wall. I got the myText variable to accept the TMpro button text, but now I'm getting an error that reads as the following any time I start up.

    "
    NullReferenceException: Object reference not set to an instance of an object
    EvidenceListButton.SetText (System.String textString) (at Assets/UI/EvidenceListButton.cs:16)
    EvidenceListControl.Start () (at Assets/UI/EvidenceListControl.cs:18)
    "

    At this point, it just feels like I'm mentally missing something I need to get this working. Maybe something obvious. So, I figured I'd take a break and ask here to figure out what's going on. Below, I've attached pictures of the two relevant scripts. I can throw in more if need be.

    If you can help me figure out where I'm going wrong, that would be much appreciated. Thanks.

    Screenshot (1041).png Screenshot (1042).png