Search Unity

Bug TMP causes crash when an instantiated UI element has TMP elements on it.

Discussion in 'UGUI & TextMesh Pro' started by The702Guy1, Feb 28, 2023.

  1. The702Guy1

    The702Guy1

    Joined:
    Apr 24, 2022
    Posts:
    48
    I have verified that indeed it is a crash related to TMP because of an error code and because if I replace all of the TMP_Text on the instantiated object with legacy Text elements, everything works as intended. I am instantiating an image that has various TMP text components on it. The app is running on android.

    Method that causes the crash:

    Code (CSharp):
    1. public void InitializeButtonData(Dictionary<string, object> data, GameObject gunIcon)
    2.     {
    3.         Debug.Log($"DEBUGTEST: Initializing button data for {data["Gun Name"]}");
    4.  
    5.         gunCardsScreen = GameObject.Find("Gun Cards").transform;
    6.  
    7.         Debug.Log($"DEBUGTEST: Gun cards screen found for {data["Gun Name"]}");
    8.  
    9.         gunData = data;
    10.  
    11.         Debug.Log($"DEBUGTEST: gunData assigned for {data["Gun Name"]}");
    12.  
    13.         //The debug above this is the last successful part of the code until the crash.
    14.  
    15.         _gunCardForThisButton = Instantiate(gunCardPrefab, gunCardsScreen.position, Quaternion.identity, gunCardsScreen);
    16.  
    17.         Debug.Log($"DEBUGTEST: gun card instantiated for {data["Gun Name"]}");
    18.  
    19.         _gunCardForThisButton.GetComponent<GunCardLogic>().SetCardInfo(data, gunIcon, GetGunRarityBackground(data["Rarity"].ToString()));
    20.  
    21.         Debug.Log($"DEBUGTEST: SetCardInfo called inside button logic for {data["Gun Name"]}");
    22.  
    23.         _gunCardForThisButton.SetActive(false);
    24.  
    25.         Debug.Log($"DEBUGTEST: card set inactive for {data["Gun Name"]}");
    26.  
    27.         this.GetComponent<Button>().onClick.AddListener(OpenGunCard);
    28.  
    29.         Debug.Log($"DEBUGTEST: Button data initialization complete for {data["Gun Name"]}");
    30.     }
    Error code pulled from LogCat:

    Graphics device is null. TMPro.TextMeshProUGUI:Awake() UnityEngine.Object:Internal_InstantiateSingleWithParent(Object, Transform, Vector3, Quaternion) UnityEngine.Object:Instantiate(Object, Vector3, Quaternion, Transform) UnityEngine.Object:Instantiate(T, Vector3, Quaternion, Transform) GunButtonLogic:InitializeButtonData(Dictionary`2, GameObject) LoadoutMenuUI:SetPlayerGunsList(List`1) <GetAllGunsInInventory>d__19:MoveNext() System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean) System.Runtime.CompilerServices.MoveNextRunner:Run() System.Threading.Tasks.AwaitTaskContinuation:RunOrScheduleAction(Action, Boolean, Task&) System.Threading.Tasks.Task:FinishContinuations() System.Threading.Tasks.Task:Finish(Boolean) System.Threading.Tasks.Task:ExecuteWithThreadLocal(Task&) System.Threading.Tasks.Task:ExecuteEntry(Boolean) System.Threading.ThreadPoolWorkQueue: Dispatch()