Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

SteamVR + Raycasting - nullreference.... not set to instance of object...

Discussion in 'AR/VR (XR) Discussion' started by Vaupell, Mar 25, 2020.

  1. Vaupell

    Vaupell

    Joined:
    Dec 2, 2013
    Posts:
    166
    Dear all ;)

    Using steamVR and find it lacking, so trying to modify the "SteamVR_LaserPointer.CS"
    to be able to do remote/pickup grab..

    But only a few minuttes in, and i'm hitting a wall.

    1. I added the Laser pointer cs from Steamvr extras to the "right hand" on the player..
    And it works like a charm, i get raycast targets, get the name etc.

    2. I get the error on lines 157 & 160.. That is the two lines where i try to get info from the raycast.

    Here is what i added to the script..

    the initial stuff
    Code (CSharp):
    1.  
    2. using Valve.VR.InteractionSystem;
    3.  
    some declarations
    Code (CSharp):
    1.                
    2.         private Hand hand;
    3.         public GameObject targetGrab;   // empty, used to store what eventually will be grabbed.
    4.         private Interactable interactable;
    5.         public float moveToHandSpeed = 5f;
    6.  

    and the code,, around line 145ish..
    Code (CSharp):
    1.                
    2.  
    3.                 Debug.Log("hit - " + hit.collider.gameObject.name);  //  NULL REF ERROR (only sometimes)
    4.  
    5.                 // TO DO,, LATER, check if object is interactable.... check components..
    6.                 targetGrab = hit.collider.gameObject;  //  NULL REF ERROR
    7.  
    8.                 GrabTypes grabtype = hand.GetGrabStarting();
    9.                 bool isGrabEnding = hand.IsGrabEnding(targetGrab);
    10.  
    11.                 if (interactable.attachedToHand == null && grabtype != GrabTypes.None)
    12.                 {
    13.                     float step = moveToHandSpeed * Time.deltaTime;
    14.                     targetGrab.transform.position = Vector3.MoveTowards(transform.position, targetGrab.transform.position, step);
    15.                     hand.AttachObject(targetGrab, grabtype);
    16.                 } else if (isGrabEnding)
    17.                 {
    18.                     hand.DetachObject(targetGrab);
    19.                 }
    Any ideas? i test on some spheres i created, they can be interacted and used normally in VR.
     
unityunity