Raycast2D checking tag returns error


idk how to start this :slight_smile:
So, when i try to compare tag i am getting error at runtime stating

NullReferenceException: Object reference not set to an instance of an object

if i use (hitcomp.collider != null) everything works fine.

But i need to check the tag for implementing what i really want.

// paste code here

Thank You all!!

Double click on the exception and see where exactly, which line, is it coming from.
You access transform.tag, but if your racyast doesn’t hit anything, transform is null and you get the exceprtion. Check if the transform isn’t null first.