Search Unity

are you missing a using directive or an assembly reference? No. It's in the package folder.

Discussion in 'AR/VR (XR) Discussion' started by CWatsonT2, Apr 26, 2022.

  1. CWatsonT2

    CWatsonT2

    Joined:
    Jan 9, 2019
    Posts:
    114
    I got a new computer and installed Unity. Now I'm getting errors. In Visual Studio there aren't any errors with the code. It knows about the WebXR package (ie using WebXR) but in Unity I get this error:

    Assets\Scripts\ControllerTriggerTest.cs(4,7): error CS0246: The type or namespace name 'WebXR' could not be found (are you missing a using directive or an assembly reference?)

    WebXR is in the Packages folder and it works fine it just won't let me talk to it. What is different here?

    Here's my code and nothing is red in Visual Studio:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using WebXR;
    5.  
    6. public class ControllerTriggerTest : MonoBehaviour
    7. {
    8.     public WebXRController webXRController;
    9.  
    10.     // Update is called once per frame
    11.     void Update()
    12.     {
    13.         Debug.Log(webXRController.GetButtonDown(WebXRController.ButtonTypes.Trigger));
    14.     }
    15. }
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    It looks like WebXR works with WebGL, is your editor currently targetting WebGL?
     
  3. CWatsonT2

    CWatsonT2

    Joined:
    Jan 9, 2019
    Posts:
    114
    Yep. If I remove my personal code it builds and runs fine via WebVR on the Quest 2. So the libraries work just fine. I just can't write my own code that uses the WebVR libraries for some reason.
     
  4. kyte

    kyte

    Joined:
    Oct 16, 2013
    Posts:
    5
    Based on the part of the error message " or an assembly reference", is it possible your Scripts folder has an Assembly Definition file in it? If so, that file would need to reference WebXR package's assembly definition in its Assembly Definition Reference list.
     
    KyryloKuzyk likes this.
  5. CWatsonT2

    CWatsonT2

    Joined:
    Jan 9, 2019
    Posts:
    114
    This was the answer. I had to create an Assembly Definition and add WebVR. Then it worked fine. Thank you so much!