Finding parent of collider, using boxoverlap.
Here is my code:
Collider2D objectOverlapped = Physics2D.OverlapBox(playerPos, size, 0);
GameObject objectParent = objectOverlapped.transform.parent.gameObject;
I'm first getting the Collider2D of the object in the OverlapBox, then in the second line im finding the parent of said collider. Any ways I can fix this, the error im getting is.
NullReferenceException: Object reference not set to an instance of an object
SelectOverlap.Update () (at Assets/Scripts/SelectOverlap.cs:34)
Thanks in advance.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613034001im_/https://answers.unity.com/themes/thub/images/avi.jpg)