Just for learning purposes, I am working on adding VR integration to the FPS Microgame using XR.
I got the camera, movement and some basic actions working.
But now, from one of my own scripts I need to get a reference to the XRController script to manually add the model for the left-hand controller.
The problem is that I can not import that script.
The error is:
Assets\FPS\Scripts\Gameplay\Managers\PlayerWeaponsManager.cs(5,22): error CS0234: The type or namespace name 'Interaction' does not exist in the namespace 'UnityEngine.XR' (are you missing an assembly reference?)
My script looks like this:
using System.Collections.Generic;
using Unity.FPS.Game;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.XR.Interaction.Toolkit; // here is the error
Do anyone know why Unity is able to see and use the script but Visual Studio doesn’t?
Going to Preferences > External Tools to check all the packages sources and then Regenerating the project files makes it possible to use the XRController from my script in Visual Studio.
It looks like you need to add the “XR Interaction Toolkit” package in the Package Manager. I believe it’s still in preview, so you’ll have to enable the “Show Preview Packages” option.
It is already enabled. I am sure of that because without that package the integration wouldn’t work at all. And that part is working already.
I can use the controls to move the character, perform some actions, move the head and all of that.
The XRController script included in that package is available to use in Unity:
And others scripts too:
The problem happens when I try to use scripts from the UnityEngine.XR.Interaction.Toolkit namespace. They are not available from Visual Studio, and if I save the code anyways it fails when unity tries to build the code.
The Interaction Toolkit is separate from the rest of the XR system. It has to be added separately and nothing you’ve shown so far demonstrates that it’s installed.
Ahh, ok, I did not know that, I thought everything was included when installing the XR Plug-in Managment.
And because everything works except importing the scripts I thought my setup was ok.
I just downloaded the project Create-with-VR_2020LTS.zip from this course Create with VR, and guess what?
It works! In that project I am able to use the XRController from the namespace UnityEngine.XR.Interaction.Toolkit.
So there is something wrong with my project.
I will just forget everything I learned from XR and start from scratch with the Oculus Integration from the asset store. Maybe I have better luck there.
I did not believe it at first either but the VSCode Unity Package version 1.2.4 causes this issue, after downgrading to 1.2.3 by manually setting that version in the manifest.json file again it works including code navigation etc.
The project linked above probably has this version set in its package manifest as well.
As fleity said, I ran into this as well, despite having all the correct packages installed, etc. Updating the manifest did not work for me, but I was able to fix it by Regenerating Project Files in Preferences<External Tools
yesterday I encountered the issue again, on a different more or less brand new project. however I explicetely had to omit registry packages from that list to make it work (even with version 1.2.3)
If you are using Unit tests in Unity OR you simply have created your own Assembly Definition Assets for compile-speed enhancement reasons, then you might simply have forgotten to add theUnity.XR.Interaction.Toolkit to your Scripts-Assembly.
It might even have happened, that you have accidentally added only the Unity.XR.Interactions.Editor assembly to your own assembly instead of the non-editor one.
If you don’t know, what assemblies are, then the problem lies somewhere else and it has nothing to do with assemblies. In this case it makes more sense to follow the above shown solutions.
I had same issue where none of the above suggestion was helping me to regenerate csproj files for Interaction Toolkit.
I was using VS 2022 as external tool but when I downgrade it to VS 2019, csproj’s were generated for all packages and hence everything was fine after that.