Skip to main content
Post Closed as "Duplicate" by Vaillancourt
name was not the case. I changed the code
Source Link

I have a line:

private void OnTriggerEnter2D(Collider2D collider)
{
   checkID = compareCollidercollider.GetComponent<PartInfo>().ID;
}

That PartInfo.cs:

using System;
using UnityEngine;

public class PartInfo : MonoBehaviour
{
    [SerializeField] int id = 0;
    GameObject parent = null;

    public int ID { get { return id; } }
}

So I see this error on "checkID =" line. I don't understand why. Help me understand it, please :)

I have a line:

private void OnTriggerEnter2D(Collider2D collider)
{
   checkID = compareCollider.GetComponent<PartInfo>().ID;
}

That PartInfo.cs:

using System;
using UnityEngine;

public class PartInfo : MonoBehaviour
{
    [SerializeField] int id = 0;
    GameObject parent = null;

    public int ID { get { return id; } }
}

So I see this error on "checkID =" line. I don't understand why. Help me understand it, please :)

I have a line:

private void OnTriggerEnter2D(Collider2D collider)
{
   checkID = collider.GetComponent<PartInfo>().ID;
}

That PartInfo.cs:

using System;
using UnityEngine;

public class PartInfo : MonoBehaviour
{
    [SerializeField] int id = 0;
    GameObject parent = null;

    public int ID { get { return id; } }
}

So I see this error on "checkID =" line. I don't understand why. Help me understand it, please :)

Source Link

NullReferenceException. Why?

I have a line:

private void OnTriggerEnter2D(Collider2D collider)
{
   checkID = compareCollider.GetComponent<PartInfo>().ID;
}

That PartInfo.cs:

using System;
using UnityEngine;

public class PartInfo : MonoBehaviour
{
    [SerializeField] int id = 0;
    GameObject parent = null;

    public int ID { get { return id; } }
}

So I see this error on "checkID =" line. I don't understand why. Help me understand it, please :)