Why this if logic isnot short circuiting?
I've this script to check if the hit
RayCastHid2D variable has some gameobject with hole
tag or a parent gameobject with hole
tag when I Raycast...
if (hit.collider != null && (hit.collider.gameObject.tag == "hole" || (hit.collider.gameObject.transform.parent.gameObject != null && hit.collider.gameObject.transform.parent.tag == "hole")))
Everything is fine until if (hit.collider != null && (hit.collider.gameObject.tag == "hole" ||
but when I enter (hit.collider.gameObject.transform.parent.gameObject != null && hit.collider.gameObject.transform.parent.tag == "hole")
it throws a NullReferenceException
....
But why?
It supposed to short circuit here hit.collider.gameObject.transform.parent.gameObject != null &&
if there's no parent gameobject!
Your answer
Follow this Question
Related Questions
getting a NullReferenceException error and can't see why. 1 Answer
NullReferenceException in FiniteStateMachine with ThirdPersonCharacter 0 Answers
Object reference not set to an instance of an object - Jumping Scripts (C#) 1 Answer
Null Reference in UnityStandardAssets.Utility.WaypointProgressTracker.Update 0 Answers