Help a newbie

Even tho im following a course, im not getting the same results.

Right now im doing looting of a chest, and it does grant me gold, but the text telling the player about it dosent appear and keeps saying:
“NullReferenceException: Object reference not set to an instance of an object
FloatingTextManager.Show (System.String msg, System.Int32 fontSize, UnityEngine.Color color, UnityEngine.Vector3 position, UnityEngine.Vector3 motion, System.Single duration) (at Assets/Scripts/FloatingTextManager.cs:25)
GameManager.ShowText (System.String msg, System.Int32 fontSize, UnityEngine.Color color, UnityEngine.Vector3 position, UnityEngine.Vector3 mention, System.Single duration) (at Assets/Scripts/GameManager.cs:43)
Chest.OnCollect () (at Assets/Scripts/Chest.cs:18)
Collectable.OnCollide (UnityEngine.Collider2D coll) (at Assets/Scripts/Collectable.cs:13)
Collidable.Update () (at Assets/Scripts/Collidable.cs:30)”

I know its because somewhere in the code something is null, but im new and cant see where and i have now seen the same video 5 times

public class Chest : Collectable
{

public Sprite emptyChest;
public int goldAmount = 10;

protected override void OnCollect()
{
    if(!collected)
    {
        collected = true;
        GetComponent<SpriteRenderer>().sprite = emptyChest;
        GameManager.instance.ShowText("+" + goldAmount + " gold!",25,Color.yellow,transform.position,Vector3.up * 50, 3.0f);

    }
    
}

}

public class Collectable : Collidable
{
protected bool collected;

protected override void OnCollide(Collider2D coll)
{
    if (coll.name == "Player")
        OnCollect();
}

protected virtual void OnCollect()
{
    collected= true;
}

}

protected virtual void Update()
{
boxCollider.OverlapCollider(filter, hits);

    for (int i = 0; i < hits.Length; i++)
    {
        if (hits *== null)*

continue;
OnCollide(hits*);*
hits = null;

}
}
protected virtual void OnCollide(Collider2D coll)
{
Debug.Log(coll.name);
}
}
public class FloatingTextManager : MonoBehaviour
{
public GameObject textContainer;
public GameObject textPrefab;
private List floatingTexts = new List();
private void Update()
{
foreach(FloatingText txt in floatingTexts)
{
txt.UpdateFloatingText();
}
}
public void Show(string msg, int fontSize, Color color, Vector3 position, Vector3 motion, float duration)
{
FloatingText floatingText = GetFloatingText();
floatingText.txt.text = msg;
floatingText.txt.fontSize = fontSize;
floatingText.txt.color = color;
floatingText.go.transform.position = Camera.main.WorldToScreenPoint(position);
floatingText.motion = motion;
floatingText.duration = duration;
floatingText.Show();
}
private FloatingText GetFloatingText()
{
FloatingText txt = floatingTexts.Find(t => !t.active);
if(txt == null)
{
txt = new FloatingText();
txt.go = Instantiate(textPrefab);
txt.go.transform.SetParent(textContainer.transform);
txt.txt = txt.go.GetComponent();
floatingTexts.Add(txt);
}
return txt;
}
}
public class GameManager : MonoBehaviour
{
public static GameManager instance;
private void Awake()
{
if(GameManager.instance != null)
{
Destroy(gameObject);
return;
}
instance = this;
SceneManager.sceneLoaded += LoadState;
DontDestroyOnLoad(gameObject);

}
public List playerSprites;
public List weaponSprites;
public List weaponPrices;
public List xpTable;
public Player player;
public FloatingTextManager floatingTextManager;
public int gold;
public int experience;
public void ShowText(string msg, int fontSize, Color color, Vector3 position, Vector3 mention, float duration)
{
floatingTextManager.Show(msg, fontSize, color, position, mention, duration);
}
// Save state
/*
* INT preferedSkin
* INT gold
* INT experience
* INT weaponLevel
*/
public void SaveState()
{
string s = “”;
s += “0” + “|”;
s += gold.ToString() + “|”;
s += experience.ToString() + “|”;
s += “0”;
PlayerPrefs.SetString(“SaveState”, s);

}
public void LoadState(Scene s, LoadSceneMode mode)
{
if (!PlayerPrefs.HasKey(“SaveState”))
return;
string[] data = PlayerPrefs.GetString(“SaveState”).Split(‘|’);
gold = int.Parse(data[1]);
experience = int.Parse(data[2]);
Debug.Log(“LoadState”);
}
}

Hello, the first line in the stacktrace with a reference to a script and a line number tells you, where the error occurred, which is method FloatingTextManager.Show() at Assets/Scripts/FloatingTextManager.cs:25 in your case. All following lines like this tell you the route to this call.

Because line info is broken in your posted code, i could only guess, so check whats happening on the line mentioned above and what could be null (and why :)). Best would be to use a debugger to see whats happening :wink: