Search Unity

anyone know why this is giving me an invalid cast exception error?

Discussion in 'Daydream' started by pfreema1, May 29, 2017.

  1. pfreema1

    pfreema1

    Joined:
    Apr 5, 2017
    Posts:
    21
    Code (CSharp):
    1.  
    2. void Update ()
    3.     {
    4.  
    5.         RaycastHit hit;
    6.  
    7.  
    8.         if (GvrController.ClickButton) {
    9.  
    10.  
    11.             GvrLaserPointerImpl laserPointerImpl = (GvrLaserPointerImpl) GvrPointerManager.Pointer;
    12.             Ray ray = laserPointerImpl.PointerIntersectionRay;
    13.  
    14.  
    15.             if (Physics.Raycast(ray, out hit, 100)) {
    16.                 //print ("this is what's being clicked:  " + hit.collider.gameObject.name);
    17.  
    18.                
    19.             }
    20.         }
    21.     }

    The strange thing is, this was working before, and now it's giving me this error on the GvrLaserPointerImpl laserPointerImpl declaration line:

    InvalidCastException: Cannot cast from source type to destination type.

    From what I remember, the only thing I did (after I made sure the above code was working fine) was mess with the lightmap on a completely different scene that wasn't using this script.
     
  2. reedny

    reedny

    Joined:
    Mar 4, 2017
    Posts:
    57
    That compiles fine for me in VS Community 2017.
    Is that the only error in the compile? Any warnings?
    Did you get a line number for the error?
    Maybe a side-effect of something else.
     
  3. pfreema1

    pfreema1

    Joined:
    Apr 5, 2017
    Posts:
    21
    So weird. I reimported the Gvr sdk. It started working again. I modified some other scenes I'm working on. Came back to the scene with the above code, and it stopped working again. Same error. No other errors, no warnings.

    In the other scenes I'm working on, I'm not touching any of the Gvr sdk stuff.

    EDIT: Ok I figured out what the problem was....I think...If I turn off the GvrReticlePointer (which I don't want anyways) it works fine. Not entirely sure why that would give the above error though.
     
    Last edited: May 29, 2017