This question was 
             closed Jun 29, 2017 at 08:19 PM by 
             Hellium for the following reason: 
             
 
            FAQ : Some reasons for getting a post rejected : Posting about a specific compiling error or NullReferenceException
 
               Question by 
               nf1021 · Jun 29, 2017 at 08:15 PM · 
                nullreferenceexceptionraycasting  
              
 
              NullReferenceException on Raycast
My code prints out "before the condition check" and give the exception and doesn't go any farther for logging the output.
            Vector3 GazeDirection = Camera.main.transform.forward;
             Vector3 HeadPosition = Camera.main.transform.position;
             RaycastHit hitInfo;
             Debug.Log("before the condition check");
             if (Physics.Raycast(HeadPosition, GazeDirection, out hitInfo,
                     30.0f, spatialMappingManager.LayerMask))
             {
                 Debug.Log("head postion: " + HeadPosition);
                 Debug.Log("gaze direction: " + GazeDirection);
                // Debug.Log("hit info: " + hitInfo);
                 Debug.Log("distance" + hitInfo.distance);
                 if (hitInfo.distance < 2.0f)
                 {
                     Debug.Log("distance" + hitInfo.distance);
                     hitInfo.collider.gameObject.transform.parent.GetChild(0).gameObject.SetActive(false);
 
              
               Comment
              
 
               
              Follow this Question
Related Questions
Raycast2D hit.point is zero ? 0 Answers
NullReferenceException while raycasting? 0 Answers
Raycasting through UI Image with transparent part 5 Answers
Select from multiple character to move 0 Answers
Ray-casting Problem 0 Answers