Question about generating connecting objects to another when touching a trigger

What does it mean by object reference is not set to an instance of an object
Edit: the errors on line 24

using System.Reflection.Emit;
using Unity.VisualScripting;
using UnityEngine;

public class Generation : MonoBehaviour
{
    public GameObject room;
    private int currentroomXPos = 0;
    private int currentroomYPos = 0;
    int Direction;
    private int [] Xarays;
    private int [] Yarrays;
    int k = 0;
    public void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            generateRoom();
        }
    }
    private void generateRoom()
    {
        start:
        for (int i = 0; i < Xarays.Length; i++)
        {
            if (currentroomXPos != Xarays[i] && currentroomYPos != Yarrays[i])
            {
                Instantiate(room, new Vector3(room.transform.position.x + currentroomXPos,0,room.transform.position.y + currentroomYPos), Quaternion.identity);
                Xarays[Xarays.Length] = currentroomXPos;
                Yarrays[Yarrays.Length] = currentroomYPos;
            }
            else
            {
                k++;
            }
        }
        if (k == Xarays.Length)
        {
            k = 0;
            goto start;
        }
        else
        {
            k = 0;
        }

        Direction = Random.Range(1, 4);
        if (Direction == 1)
        {
            currentroomXPos += 10;
        }
        if (Direction == 2)
        {
            currentroomXPos -= 10;
        }
        if (Direction == 3)
        {
            currentroomYPos += 10;
        }
        if (Direction == 4)
        {
            currentroomYPos -= 10;
        }
    }
}    

Which line? line numbers at the end of the message ie “blabla.cs(123:33)” which is line and character number.

Is room assigned in the Inspector? It may be null if you try to instantiate it.

These issues are easy to figure out yourself by using the debugger.

It means the same thing ALWAYS.

How to fix a NullReferenceException error

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

NullReference is the single most common error while programming. Fixing it is always the same.

Some notes on how to fix a NullReferenceException error in Unity3D:

http://plbm.com/?p=221

It’s in line 24

I have no clue how to do any of this
I started coding in C# a week ago

AWESOME! Welcome to it.

Learning programming is done by doing programming.

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Here are a few great resources to get you underway:

Imphenzia / imphenzia - super-basic Unity tutorial:

Jason Weimann:

Brackeys super-basic Unity Tutorial series:

Sebastian Lague Intro to Game Development with Unity and C#: