ERROR

This is going to sound like a super unoriginal reason to post a thread but there is an error that I’m am having trouble solving.
the error text is as follows:

nullReferenceException: Object reference not set to an instance of an object
BattleUnit.Setup () (at Assets/Scripts/Battle/BattleUnit.cs:18)
BattleSystem.SetupBattle () (at Assets/Scripts/Battle/BattleSystem.cs:17)
BattleSystem.Start () (at Assets/Scripts/Battle/BattleSystem.cs:12)

here is the script it was talking about

public class BattleSystem : MonoBehaviour
{
    [SerializeField] BattleUnit playerUnit;
    [SerializeField] BattleHud playerHud;

    private void Start()
    {
        SetupBattle();
    }

    public void SetupBattle()
    {
        playerUnit.Setup();
        playerHud.SetData(playerUnit.Pokemon);
    }
}

plz help!!!

The answer is always the same… ALWAYS!

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Three steps to success:

  • Identify what is null ← any other action taken before this step is WASTED TIME
  • Identify why it is null
  • Fix that

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

yes you said this to all of the other similar errors I’ve seen but it wasn’t working for me

Do you mean you are unable to discern what is null?

If so then you probably need to set this project gently aside and start with some basic C# tutorials.

Read the error. The null ref isn’t even in this script. It’s in BattleUnit, line 18.

Oh as you can see I I had a variable of toe BattleUnit and thought it was referring to that! Thanks!