I've been looking around for a possible solution but I don't solve It... This is the problem:
I have in a file with its class the various Ui, including the textmesh.
Another file, with its own class, retrieves and sets them via ".text"
result?
"NullReferenceException: Object reference not set to an instance of an object Controller_RaceManager.Update () (at Assets/[GameAssets]/Controller [MobileCar]/Scripts.Code/Controller_RaceManager.cs:307)"
to better understand:
A) into Controller_UiManager.cs (attached to the canvas with all UIs)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI; using TMPro;
public class Controller_UiManager : MonoBehaviour
{
[System.Serializable]
public class UiSettings
{
public TextMeshProUGUI Label_Lap;
}
[SerializeField]
[HideLabel] public UiSettings UiElements;
void OnDrawGizmos()
{
var Canvas = this.gameObject;
UiElements.Label_Lap = getTheChild(Canvas, "Label.PilotLap").transform.GetComponent<TextMeshProUGUI>();
// note: getTheChild is a method that returns the child gameObject
}
}
B) Controller_RaceManager.cs, which of course handles all the values โโof races (It's attached to his prefab for loops and bla bla bla)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; using TMPro;
public class Controller_RaceManager : MonoBehaviour
{
[System.Serializable]
public class RaceManagerSettings
{
...
public Controller_UiManager UiManager;
}
[SerializeField]
[HideLabel] public RaceManagerSettings sets;
void OnDrawGizmos()
{
if(GameObject.Find("Ui-RaceLoop"))
{
sets.UiManager = GameObject.Find("Ui-RaceLoop").transform.GetComponent<Controller_UiManager>();
}
else
{
Debug.LogError("Controller Race Manage: Ui System not founded - Ui-Raceloop prefab is not in scene");
}
}
void Update()
{
string Label_Lap_Output = "";
if(...) { Label_Lap_Output = "FINISHED";}
else if(....) { Label_Lap_Output = "LAP XX/"+totalloopText; }
else { Label_Lap_Output = "LAP O"+pilotlapText+"/"+totalloopText; }
sets.UiManager.UiElements.Label_Lap.text = Label_Lap_Output;
}
}
here unity pauses and gives notice. If I take the break, it continues quietly ... but am I becoming stupid?
is there a reason?
note: Unity TextMeshProUGUI.text is NullReference not "why not all or some things" ... but textmeshpro.