'TextMeshPro doesn't want to change in Unity

I have a tank, that has level. Tank is a prefab. Tank should show his level using TextMeshPro:

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

public class TankEnd : MonoBehaviour
{
    GroundSpawner groundSpawner;

    public TextMeshProUGUI levelText;

    public int level; 

    void Start()
    {
        levelText = GameObject.Find("TankEndLevelText").GetComponent<TextMeshProUGUI>();
        groundSpawner = GameObject.Find("GroundSpawner").GetComponent<GroundSpawner>();
        
        level = groundSpawner.level;
        levelText.text = "Level: " + level;
    }

}

But it doesn't changes. I have an error:

NullReferenceException: Object reference not set to an instance of an object TankEnd.Start () (at Assets/Scripts/Tank/TankEnd.cs:23)

How to fix this? I think tank script can't find level text.



Solution 1:[1]

Do you need the GameObject.Find method? I'd suggest assigning it in the editor if possible or just double check the name, in case it changed somehow

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Winjas Force