Inspector changes set TextMeshPro values on play

Im really stuck here and struggling to figure out what the hell is going on.

I have this script attached to a gameobject. It points to various TextMeshPro UI elements and in theory (I have done this before with standard text and it worked fine) it should work, but when I hit play, the inspector gets rid of the things I have set. I have included screenshots as I dont know how to word this properly. Thank you.


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

public class Questions : MonoBehaviour
{

    public TextMeshProUGUI question;
    public TextMeshProUGUI answera;
    public TextMeshProUGUI answerb;
    public TextMeshProUGUI answerc;

    public string questiontext;
    private string answeratext;
    private string answerbtext;
    private string answerctext;



    void Start()
    {
        question = GetComponent<TextMeshProUGUI>();
        answera = GetComponent<TextMeshProUGUI>();
        answerb = GetComponent<TextMeshProUGUI>();
        answerc = GetComponent<TextMeshProUGUI>();

        questiontext = "When asked to dice an onion, or similar ingredient. What shape do you expect to find the final product?";

        answeratext = "cubes";
        answerbtext = "strips";
        answerctext = "rounds";
    }


    void Update()
    {
        question.text = questiontext.ToString();
        answera.text = answeratext.ToString();
        answerb.text = answerbtext.ToString();
        answerc.text = answerctext.ToString();

    }
}

151577-notplay.png

151578-onplay.png

when you set your textmeshpro variables in editor, don’t override them when you start the game.

void Start()
     {
         question = GetComponent<TextMeshProUGUI>();
         answera = GetComponent<TextMeshProUGUI>();
         answerb = GetComponent<TextMeshProUGUI>();
         answerc = GetComponent<TextMeshProUGUI>();
     }

get rid of that bit, you’re trying to reset your TextMeshProUGUI components to a component that you;re trying to get on an object that has the Questions script attached to it. (and they’re all null because that object doesn’t have any TextMeshProUGUI components on itself)