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 :)
compareCollideris null. 2. ComponentPartInfois null, i.e., the part info was not found. Either fix the underlying or write:checkID = compareCollider?.GetComponent<PartInfo>()?.ID ?? 0;\$\endgroup\$colliderand you check forcompareCollider. \$\endgroup\$