Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug UI TMP Text Disappearing in Build

Discussion in 'UGUI & TextMesh Pro' started by chenry22, Jun 8, 2023.

  1. chenry22

    chenry22

    Joined:
    Jan 28, 2022
    Posts:
    1
    I'm a little new to Unity and I've been testing a build of a project I've been working on and have been stumped on a really weird problem. Whenever I run my code in the Unity Editor everything works perfectly, but in the build created there is something wrong with the UI. Basically after a specific scene is loaded, all TMP Text disappears in all scenes of the game. What's weird to me is that before this scene, the text all works fine even in different resolutions and scales correctly to the screen size. It's just this one scene that seems to break everything, even in scenes loaded before it. I've looked at the Player logs and I'm not getting any errors, I've messed around with Canvas rendering and Text wrapping, but nothing seems to be working. I'm attaching a copy of the code that runs when the problematic scene is loaded, but as far as I can tell nothing in it should be breaking the UI to that extent (especially not in all scenes in the project). Any advice would be really appreciated, I really want to get this project to work and this is the one thing that is messing up my build. Also I should probably note that I'm using an old version of Unity (2020.3.15f2), in case that changes anything.

    Code ran on scene load:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using TMPro;

    public class GameOneScript : MonoBehaviour
    {
    public static bool perfect = true;
    public int perfectBonus = 3;

    public float timer = 10f;
    public static int scoreAdd = 0;
    public static bool gameRun = false;
    public float gameTime = 10f;
    public TMP_Text timeText;
    public TMP_Text scoreText;

    // Start is called before the first frame update
    void Start()
    {
    perfect = true;
    scoreAdd = 0;
    gameRun = true;
    Matching.gameState = 1;
    Debug.Log("Game State: " + Matching.gameState);
    StartCoroutine(gameRunner());
    }

    IEnumerator gameRunner(){
    while(gameRun){
    yield return null;
    }

    if(perfect){
    scoreAdd += perfectBonus;
    }

    Matching.score += scoreAdd;
    Debug.Log("Adding score: " + scoreAdd);
    SceneManager.LoadScene("MainGame");
    }

    IEnumerator waitRead(float time){
    yield return new WaitForSeconds(time);
    }

    void Update(){
    if(gameRun){
    Matching.globalCountdown -= Time.deltaTime;
    timer -= Time.deltaTime;
    if(timer < 0){
    gameRun = false;
    }

    updateDisplay(timer);
    }
    }

    void updateDisplay(float time){
    float seconds = 1 + Mathf.FloorToInt(time % 60);
    timeText.text = "Time: " + seconds ;
    scoreText.text = "Score: " + scoreAdd;
    }
    }