Thank you so much! Im just getting started with Unity and vr-Dev and its so frustrating that the Unity-interface has changed so much in one year and its hard to set the inputs right with all the different Versions people in Tutorials explain! So thankful to find you explaining it propperly for the setup in 2021.
Sweet! This is supported natively now! 5 months before this video came out, i had Modified XR's Controller script to have public faceing functions so i could pass though Select and Activate actions via script. In a hakish way i could still use unitys Input system for all the controlls, and still pass them through to VR. Allowed me to simultaneously have keyboard, mouse, gamepad and oculus controller trigger things like teleportation. After seeing this video, i can now revisit this and do it properly without the need for modified library code as this type of functionality is now natively suported between the input system with the XR toolkit! Thanks!
By the way, the presets that you download do not have to be added to the 'Preset Manager' and labeled 'left' and 'right'. You can just create an XRRig, and then click on the individual left and right controllers, and choose the presets by clicking on the small 'preset' button in the inspector at the top right, by the help and more buttons. Thought I'd share since I ran into that!
Thanks Andrew! Had just read up on the new input system and I learned about it in terms of normal kB &mouse & gamepads, so it was nice to see how it applies to the XR toolkit now! :)
Awesome! Can't wait for an update to the interaction system with this new method, especially the new hand interaction / posing stuff. Also really happy to finally be able to leave the legacy vr system for cross platform setup.
It's limited Index Support in Unity 2019. You'll need to keep a look out for Unity's Beta OpenXR integration that'll hopefully be out by the end of the year.
How can I read trigger value with the new input system? meaning I want to poll in update for the current amount the trigger is pressed, giving values between 0-1. The Activate action in the default set seems to only be a button.
Thanks for the dope tut. I had a question how can you then use the inputs? when I first looked at new input system, a couple days ago, I used the Player Input component to gain access to the actions. but with the right and left controller being separate action maps you can only use one or the other for the Player Input. Im just not sure how to actually use the input to do things now.
There may be a more permanent solution in the future, but the Input Action Manager kinda does what the Player Input component does. Only that it enables all of the Actions within each Action Set, instead of how the Player Input does it on a per Action Set basis. One way of checking for additional Input is to use the Input Action References. There should be a section on how to do this in the New Input System manual. docs.unity3d.com/Packages/com.unity.inputsystem@0.2/manual/Actions.html
This is great, thank you! Now I am having issues using the XR Device Simulator when trying to control the virtual HMD. I am trying to apply the same principals but I can't seem to get it.
I tried the Device Simulator awhile back and for whatever reason, I struggled to get it to do a whole lot. It's still real early, and not well documented so I haven't done too much with it.
Thank you for the video! It helped a lot. Just wondering if there is an easy way to also add primary and secondary buttons because I noticed they were not added by default
Yeah! It just depends if you're just doing the basic inputs, or have it work on the currently selected object. For the basics, I'd say look into a generic New Input System video for creating actions. You can then create a new action either using the Generic XR Controller or specifically Vive and Index if you're using OpenXR.
Might be a stupid question, but when I click RMB in Hierarchy it shows only XR options without "(Action-based)", what could be wrong? Also when I click on Default Input Actions Presets - Inspector says "Unable to load this Preset, the type is not supported" =(
Double-check you're on a more recent version, and that there isn't a submenu for action-based components. You're only able to apply presets if you're using the correct component. Which, may explain why you can't apply the action presets.
@@VRwithAndrew Thanks! After I've updated OpenXR from 1.2.6 to 1.2.8 it finally appeared! Or editor just needed a reload for something to be applied, idk honestly, but I'm happy now, thank you!)
Hello, I'm trying to use this action-base input system but I can not give the "XRI Default Input Actions" Asset to my script, it does not show up in the inspector ; do you have any idea ? I did this [SerializeField] public XRIDefaultInputActions Controls;
@@VRwithAndrew Thanks for your answer ! it puts me on rails. I used XRIDefaultInputActions because I wanted to use the Unity C# generated class from the input asset package example. Giving it from the inspector like I tried to do is obsolete ; now you need to do instantiate it directly from code like this : var test = new XRIDefaultInputActions();
Thanks for the info, I have been struggling for hours before watching your video. Now I could finally make the controllers work! However I have a problem with the camera, it doesnt seem to be tracking, not even the rotation. I have the project set with the new input system and followed your instructions. Headset is an Oculus Quest 2. Any suggestion? Thanks!!
@@VRwithAndrew Thanks for your help, it was in the Camera, Track Pose Driver (New Input System), I had to put Position and Rotation Action to specifically target Oculus Headset, any other preset won't work. You pointed me in the right direction!
@@egrinant2 Edgar, I encounter similar problem with you with my oculus quest. May i know which preset you are end up using ? I have tried Device and Center Eye Oculus. but none works.
@@akravatorwind8976 I was able to solve this problem by following the advice here: forum.unity.com/threads/xr-interaction-toolkit-0-10-preview-is-available.1000576/#post-6497878. My problem was Active Input Handling was set to "Input Manager (old)" in Project Settings > Player.
I have watched your videos on the action based input system multiple times but I am still confused on one thing. If you for example create an action called "test" and bind it to the primary button of the right hand controller, how can you do something when that button is pressed? I'm trying to reference a variable storing the ActionBasedController component, called controller. I can for example do bool buttonPressed = controller.selectAction.action.ReadValue(); to see if the select action is being pressed, but when I replace select with test, test beign the action I created in the action window, it wont work. Is there something else I have to do to check if an action I added is being pressed? Thx.
That should work! Make sure you've saved the Input Asset, also assuming that all your actions are also being enabled in the Input Action Manager script.
@@VRwithAndrew Oh so I would need to write another line of code to enable the "test" action that I created in the action input window? How would u do that?
@@VRwithAndrew Yeah I'm trying this but it's not working, it's telling me "testAction" isn't valid I must be missing the step to enable it if there's something additional you have to do besides adding it in the action input window: buttonPressed = controller.testAction.action.ReadValue();
@@VRwithAndrew Yeah I'm honestly just trying to run code when the primary button on the right controller is pressed it's crazy how hard this seems to be with the new input system I've seen a lot of other comments with this same issue too I don't get what I'm missing. I double click the default Input actions asset, it pops open the action input window. On the left it has XRI HMD, XRI LeftHand, and XRI RightHand. I click XRI RightHand. Then, in the middle column, I click the + symbol. I name the new action "Test", the action type parameter is set to button. Then I click the + symbol next to that and click "add binding", and I add the primaryButton binding from generic XR controller stuff. It just doesn't let me use "Test" in my code. Here is the full code I'm using: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.XR.Interaction.Toolkit; public class ActionInputTest : MonoBehaviour { private bool buttonPressed; //bool that stores true or false if button is pressed private ActionBasedController controller; private void Start() { controller = GetComponent();
Nice Tut. Is there a way to control the XR Rig via Android Smartphone? I tried to use: device rotation[HandheldARInputDevice] device rotation[OpenVR Headset] attitude[Sensor] But via Unity Remote 5 nothing happens. Do I have to set up my device differently?
That would be the Primary or Secondary button inputs for the Generic Controller. But, if you're using OpenXR you can access the inputs on a per controller basis if you want to be more specific.
@@VRwithAndrew Is there an easy way to change what those buttons do depending on other things? Like if you're holding something the primary button does one thing, but if you're holding something different it does something else?
I updated the XR Interaction Toolkit to import the Default Input Action. However, as soon as I imported it, I saw the function [protected void OnSelectEnter (XRBaseinteractor)] part of Interactables' AxisDragInteractable.cs error occurred. I want to ask if there is a solution.
@@user-wt1oq2fx8r When you're using updated version of XR Toolkit, they've updated to use EventArguments. I cover this at the beginning of my Bow and Arrow 2.0 video.
I was having issues making code run when the primaryButton on the right controller was pressed. After a real long time messing with this I was able to get it working, wanted to share in case someone else was having this issue. First, go double click your XRI Default Input Actions asset. Click XRI RightHand in the left column, and then click the + symbol in the middle column to create your action. I named mine Test, click it and set the Action Type in the right colum to button, then click the + symbol next to Test and click Add Binding. Click the new binding, and then in the path parameter in the right column navigate to the primaryButton for the XR controllers, check the "Generic XR Controller" checkbox. Once the Test action is created in the input action window you have to add it to the ActionBasedController script, this is what was throwing me off. Open that script and add the following, this will allow you to reference the Test action in other scripts: [SerializeField] InputActionProperty m_TestAction;
public InputActionProperty testAction { get => m_TestAction; set => SetInputActionProperty(ref m_TestAction, value); } Once you have done that you can reference this action in code. The buttons are weird with this system btw too, the button press will return a float and not a bool like you would think. To make something happen when the button is pressed do if (buttonPressed > 0) instead of if(buttonPressed == true), you could also create a function and have it run when the button is triggered here is the code I used: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.XR.Interaction.Toolkit; public class ActionInputTest : MonoBehaviour { private float buttonPressed; //bool that stores true or false if button is pressed private ActionBasedController controller; private void Start() { controller = GetComponent(); } void Update() { buttonPressed = controller.testAction.action.ReadValue(); if (buttonPressed > 0) { Debug.Log("Button Pressed"); } } }
If you're simply trying to read the value, you don't have include it in the controller. Also, the scripts that are included in Packages aren't saved between Unity re-loads. You can very well do the same thing using this script. github.com/C-Through/XR-OpenXR/blob/main/Assets/_OpenXR/Scripts/AssetInputExample.cs
@@VRwithAndrew Hi Andrew, sorry I'm not sure what you are explaining with this script. Are you stating that I don't need to alter the ActionBasedController using the script you provided? And yes, just simply trying to tell if the primaryButton on the right hand is pushed, and if it gets pushed run some code. I'm still not understanding how the script you provided would allow me to access an action I create called Test. I'm honestly finding all of this new system very confusing though the scripting part anyway so it's probably just not making sense to me. I get the concept, like setting up actions and then writing code to act off of the action instead of a specific controller so it can be easily reconfigured, but the coding required to do something as simple as telling if a button is pressed pretty just makes it a headache.
@@VRwithAndrew I think I get what you are saying now thx. Instead of adding the testAction to your controller, you could just create a script and then declare a public InputActionReference variable named test for example, and then drag the testAction from the asset window in that, and then just do buttonPressed = test.action.ReadValue(); to read the value, or do the test.action.started or performed if you just want something to happen when the button is pressed. Sounds like you could do action.ReadValue in an update function or use action.performed from a start function in your doPerformedThing example, is one method better than the other or is there a difference I'm not understanding? thx
If you look into more generic Input System videos, they should show you how to use the ReadValue function. I touch on it at the end of my OpenXR video.
Is there a tldr on how to setup a new action? I'm trying to subscribe to a primary button action, set it up in the action menu and mapped it to generic XR left hand. How can I access this in code to subscribe to the event, though?
so there's a rotation "action" but how do you actually get the rotation out of it ? the only parameter is a callback: controller.rotationAction.action.performed += (UnityEngine.InputSystem.InputAction.CallbackContext obj) => { };
All of those actions are set up to select, activate, and all that. If you're trying to do additional actions for the XR Controller, it's possible but overly in-depth to do. I do cover more customization for actions in my Custom XR Actions video.
How do I use this if I want a debug.log when I press A,B X or Y on my Quest2? Do you have a script for that? Been searching for this info the past 4 days, can't move on until I know how.
I'm putting together a simple project on this since it's a very common question. In the meantime, I would recommend looking into more generic Input System videos, and my OpenXR video. It has some info on input as well.
Hey man i just wanted to know if it possible to create a spectator camera inside a vr scene with unity xr input management. I wanted to make a controlable spectator camera with mouse and keyboard but the xr input wont let me
In theory, I think you'd be able to do it. If you can get the camera and everything setup correctly. You may need to look into how the Input System handles multiplayer. Or, you may be able to get away with writing your own script to Activate all of the actions, and have the functionality you want hooked up to them. You can see more of that here. docs.unity3d.com/Packages/com.unity.inputsystem@0.2/manual/Actions.html
I'm running into a problem with the action-based XR rig. I'm on an Oculus Quest 2 in Unity 2020.2. When I build and run, the scene is locked in one position. Moving my head does nothing. My controllers are also locked onto the headset's position. As a check, I ran Unity's example VR scene and had no problems on my headset. I've tried everything I can think of: building in a fresh version of Unity, building in the URP instead of 3D, and double-checking the project settings. I also deselected everything in the Unity example scene and rebuilt the room-scale action-based XR rig in there, and it worked. I must be missing a setting somewhere, but I don't know what it is. Does anyone have any idea what might be causing this, and how to fix it?
Update: I figured out the problem, sort of. If I run through the above tutorial in 2019.4, everything works. Then, if I reopen the project as a 2020.2 project, it works there as well. Unity does something in the background to update the project, not sure what but it works.
@@peterweigel2991 I was able to solve this problem by following the advice here: forum.unity.com/threads/xr-interaction-toolkit-0-10-preview-is-available.1000576/#post-6497878. My problem was Active Input Handling was set to "Input Manager (old)" in Project Settings > Player.
Everything gets funneled into the Select, and Activate via the XRController. If you're looking at more functionality, that's a bit of a process that I don't have a video on.
Have you figured out how to use this with XRGrabInteractables? i can't get onActivate to trigger, and the weapon I'm holding just rotates like it's inside of a microwave.
@@VRwithAndrew I have since figured it out. It was rotating because that's what the rotate anchor input does. I had to disable that. The trigger wasn't working because I'm a moron and I forgot that I had copied a scene (and didn't include it in the build). Thanks for the reply 😄
Thanks Andrew. I must be dumb, but wow for some reason I feel Unity is making everything somewhat more difficult. On one hand I feel getting input from controllers seems more straight forward and less (or zero) code, but on the other...there's something about how they're designing everything that makes it more annoying. Don't even get me started with ECS.
It's certainly not perfect. Unity is aware on how they've dropped the ball in some areas and trying to more transparent in the futre. The New Input System is very flexible and there are a lot of different ways of using it. However, the documentation is incredibly dense and it took me sometime to figure out how to do things. This is with my existing experience with Action-Based Input coming from SteamVR.
I need to have complex inputs, such as a different 'activation' of a selected or grabbed object for different button press events like trigger vs A vs B vs B + trigger vs A+ etc... Also, I need to have a teleport function that activates whenever you move the analogue stick forward, disabling the grab function, but I need to stop it from triggering when the grab is triggered.... I'm getting a headache with this stuff, you think you could make a video that goes into a little more detail, with some variation, and maybe even a little peek into how the scripts do their thing?
@@VRwithAndrew for instance, in VR chat, many of the animations require multiple buttons being pressed in combination. sometimes this loads an animation, or swaps out the model of the object that hand is holding. some objects, because of their size, like a shield in a combat game, could block fast movement such as teleport. (conditional suppression of teleport) you might also want to trigger this when in combat, or in menus, etc.
oh, maybe you could make essentially a code template that would point to several of the 'actions' and change what button each action is tied to, disable and enable it, and tie it to a set named object being 'selected' or spicifically 'grabbed' or 'raycast selected' you could also show it being called by a external script to simulate game state changes.
this is not to forget showing a sampling of effects these buttons could trigger, such as changing the model or triggering a particle effect, and would be good to show an example of a custom action, looks like you can just add one in the menu using the plus button at the top, but some people might not notice that. i could become a muffin supplier next month if you did this, just to get access to the template. would make a nice video though.
Not that I'm aware of, but maybe in the future. There are some pieces of documentation that additional input is possible. Right now it's exclusive to using OVR to my knowledge.
@@VRwithAndrew Thanks. I'll try again with OVR. I had difficulty getting the hands to move other rigidbodies. I added a sphere collider to each hand but the sphere appeared a meter away from the hand. Not sure where I went wrong.
@@VRwithAndrew Also, I think hand-tracking won't be viable for most tasks because it will never be able to handle occlusion with headset cameras alone.
Thank you so much! Im just getting started with Unity and vr-Dev and its so frustrating that the Unity-interface has changed so much in one year and its hard to set the inputs right with all the different Versions people in Tutorials explain! So thankful to find you explaining it propperly for the setup in 2021.
Glad to help!
amazing that you posted this today I JUST needed this.
Glad to be of assistance!
Andrew, thank you so much! My game has gone through 3 toolkits and this is now my final one. Professional to the point videos and nice voice! :)
You're very welcome, Wilko! I'm glad you enjoyed them.
This is one of the most helpful Unity tutorials, I have ever seen! Thank you so much!
Pure gold! I was having so much trouble and I was missing adding the Input Action Manager script. Thanks so much!
Happy to help!
dope! got through a hurdle, thanks man
Sweet! This is supported natively now! 5 months before this video came out, i had Modified XR's Controller script to have public faceing functions so i could pass though Select and Activate actions via script. In a hakish way i could still use unitys Input system for all the controlls, and still pass them through to VR. Allowed me to simultaneously have keyboard, mouse, gamepad and oculus controller trigger things like teleportation. After seeing this video, i can now revisit this and do it properly without the need for modified library code as this type of functionality is now natively suported between the input system with the XR toolkit! Thanks!
Happy to help!
You're my hero, I was beating my head against the terrible default Unity instructions on this all week. Cheers man.
Happy to help!
great explanation of this system, even after two years.
Happy to help!
O M G! You actually go to the documentation and explain all the "whys"! This is so awesome!
Glad you found it useful!
This is gold, thanks for keeping us up to date
Of course!
So this is how it works, didn't get my head around it for the last few days, thank you so much! :)
Glad it helped!
By the way, the presets that you download do not have to be added to the 'Preset Manager' and labeled 'left' and 'right'. You can just create an XRRig, and then click on the individual left and right controllers, and choose the presets by clicking on the small 'preset' button in the inspector at the top right, by the help and more buttons. Thought I'd share since I ran into that!
@@VeryDavidChannel Yep! This can also be found in the Presets Documentation that a pinned.
Thanks Andrew! Had just read up on the new input system and I learned about it in terms of normal kB &mouse & gamepads, so it was nice to see how it applies to the XR toolkit now! :)
You're welcome, Cedric!
Oh, man, thank you! I was missing the Input Action Manager. Great channel, very useful for beginners like me.
Happy to help, Franco!
extremely helpful tutorial. combines a lot of info in a short time. great work!
Much appreciated!
Thank you for this video!!
This is stuff that should be in the official docs to begin with.
Happy to help!
THANK YOU ANDREW YOU LOOK AFTER US HOMIE, DIVINES BLESS YOU MY MAN
Anytime, homie
best tutorial for biginner of xr toolkits . very awesome!
Much appreciated!
Awesome! Can't wait for an update to the interaction system with this new method, especially the new hand interaction / posing stuff. Also really happy to finally be able to leave the legacy vr system for cross platform setup.
Aren't we all! I'm glad we're finally getting a more straightforward solution.
GENIUS !!! I spent two days trying to understand that !
Now we're both geniuses!
Thanks for showing us the way Man. Such great content. Really appreciated.
Happy to help!
thank you so much bro, for this detailing
Happy to help!
now this is what we call progress
We're getting there!
Thank you Andrew! Your video has saved me a lot of time! :)
Happy to help, Igor!
Great video. Thanks!
Happy to help!
Does this support valve index controllers yet?
I have the same question, it would be great if someone knew this.
@@DeGandalf yeah I have been waiting for better index support for ages
It's limited Index Support in Unity 2019. You'll need to keep a look out for Unity's Beta OpenXR integration that'll hopefully be out by the end of the year.
@@VRwithAndrew Thanks! I have been using steamvr sdk for over a year and I can’t wait to switch so that I can support multiple devices!
Interesting. But how do we actually read the controller buttons ? Example A and B buttons on a meta quest controller ?
How can I read trigger value with the new input system? meaning I want to poll in update for the current amount the trigger is pressed, giving values between 0-1. The Activate action in the default set seems to only be a button.
If you go into the action set and select the Activate action. You'll just need to change it from a Button to a Value, and set it as an Axis.
Based.
Thank you!
You're welcome!
Thank you very much for this, very helpful.
You're welcome, James!
Thanks, it helps me a lot.
You're welcome, Hasan!
Thanks for the dope tut. I had a question how can you then use the inputs? when I first looked at new input system, a couple days ago, I used the Player Input component to gain access to the actions. but with the right and left controller being separate action maps you can only use one or the other for the Player Input. Im just not sure how to actually use the input to do things now.
There may be a more permanent solution in the future, but the Input Action Manager kinda does what the Player Input component does. Only that it enables all of the Actions within each Action Set, instead of how the Player Input does it on a per Action Set basis. One way of checking for additional Input is to use the Input Action References. There should be a section on how to do this in the New Input System manual.
docs.unity3d.com/Packages/com.unity.inputsystem@0.2/manual/Actions.html
Currently trying to get a button click working and it isn't. A video on that would be sweet.
I have a Custom Input Actions video that may help you.
This is great, thank you!
Now I am having issues using the XR Device Simulator when trying to control the virtual HMD. I am trying to apply the same principals but I can't seem to get it.
I tried the Device Simulator awhile back and for whatever reason, I struggled to get it to do a whole lot. It's still real early, and not well documented so I haven't done too much with it.
Briliant
Thanks!
Thank you for the video! It helped a lot. Just wondering if there is an easy way to also add primary and secondary buttons because I noticed they were not added by default
Yeah! It just depends if you're just doing the basic inputs, or have it work on the currently selected object. For the basics, I'd say look into a generic New Input System video for creating actions. You can then create a new action either using the Generic XR Controller or specifically Vive and Index if you're using OpenXR.
Awesome, Would like to use movement with Actionbased XR, any vids?
Not exactly, but I do have this video that shows how to implement XR Toolkit's built-in locomotion.
czcams.com/video/4WiMogkep1U/video.html
JEEZ! THANKS
You're welcome!
Might be a stupid question, but when I click RMB in Hierarchy it shows only XR options without "(Action-based)", what could be wrong? Also when I click on Default Input Actions Presets - Inspector says "Unable to load this Preset, the type is not supported" =(
Double-check you're on a more recent version, and that there isn't a submenu for action-based components. You're only able to apply presets if you're using the correct component. Which, may explain why you can't apply the action presets.
@@VRwithAndrew Thanks! After I've updated OpenXR from 1.2.6 to 1.2.8 it finally appeared! Or editor just needed a reload for something to be applied, idk honestly, but I'm happy now, thank you!)
Right Click > XR > "Convert Main Camera to XR Rig" ... that is my only option. What am I doing wrong?
Double-check that you've added XR Toolkit from the Package Manager.
Do you change the Main Camera's position on it's transform or the Camera Offset's transform? Thx
Main Camera's position
@@VRwithAndrew Thx!
Hello, I'm trying to use this action-base input system but I can not give the "XRI Default Input Actions" Asset to my script, it does not show up in the inspector ; do you have any idea ?
I did this [SerializeField] public XRIDefaultInputActions Controls;
You'll want to use the type "InputActionAsset" rather than "XRIDefaultInputActions".
@@VRwithAndrew Thanks for your answer ! it puts me on rails.
I used XRIDefaultInputActions because I wanted to use the Unity C# generated class from the input asset package example.
Giving it from the inspector like I tried to do is obsolete ; now you need to do instantiate it directly from code like this :
var test = new XRIDefaultInputActions();
Thanks for the info, I have been struggling for hours before watching your video. Now I could finally make the controllers work! However I have a problem with the camera, it doesnt seem to be tracking, not even the rotation. I have the project set with the new input system and followed your instructions. Headset is an Oculus Quest 2. Any suggestion? Thanks!!
I'm not sure about that! What version of Unity are you using? If you go to the Camera's GamObject, does it have an Action-Based poser on it?
@@VRwithAndrew Thanks for your help, it was in the Camera, Track Pose Driver (New Input System), I had to put Position and Rotation Action to specifically target Oculus Headset, any other preset won't work. You pointed me in the right direction!
@@egrinant2 Edgar, I encounter similar problem with you with my oculus quest.
May i know which preset you are end up using ? I have tried Device and Center Eye Oculus. but none works.
@@akravatorwind8976 centerEyePosition [Oculus Headset] and centerEyeRotation [Oculus Headset]
@@akravatorwind8976 I was able to solve this problem by following the advice here: forum.unity.com/threads/xr-interaction-toolkit-0-10-preview-is-available.1000576/#post-6497878. My problem was Active Input Handling was set to "Input Manager (old)" in Project Settings > Player.
Awesome!
Thanks!
I have watched your videos on the action based input system multiple times but I am still confused on one thing. If you for example create an action called "test" and bind it to the primary button of the right hand controller, how can you do something when that button is pressed? I'm trying to reference a variable storing the ActionBasedController component, called controller. I can for example do bool buttonPressed = controller.selectAction.action.ReadValue(); to see if the select action is being pressed, but when I replace select with test, test beign the action I created in the action window, it wont work. Is there something else I have to do to check if an action I added is being pressed? Thx.
That should work! Make sure you've saved the Input Asset, also assuming that all your actions are also being enabled in the Input Action Manager script.
@@VRwithAndrew Oh so I would need to write another line of code to enable the "test" action that I created in the action input window? How would u do that?
@@VRwithAndrew Yeah I'm trying this but it's not working, it's telling me "testAction" isn't valid I must be missing the step to enable it if there's something additional you have to do besides adding it in the action input window: buttonPressed = controller.testAction.action.ReadValue();
@@flurishart612 Depending upon how to have the action setup, you may want to try reading it as a float.
@@VRwithAndrew Yeah I'm honestly just trying to run code when the primary button on the right controller is pressed it's crazy how hard this seems to be with the new input system I've seen a lot of other comments with this same issue too I don't get what I'm missing. I double click the default Input actions asset, it pops open the action input window. On the left it has XRI HMD, XRI LeftHand, and XRI RightHand. I click XRI RightHand. Then, in the middle column, I click the + symbol. I name the new action "Test", the action type parameter is set to button. Then I click the + symbol next to that and click "add binding", and I add the primaryButton binding from generic XR controller stuff. It just doesn't let me use "Test" in my code. Here is the full code I'm using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR.Interaction.Toolkit;
public class ActionInputTest : MonoBehaviour
{
private bool buttonPressed; //bool that stores true or false if button is pressed
private ActionBasedController controller;
private void Start()
{
controller = GetComponent();
}
void Update()
{
//buttonPressed = controller.selectAction.action.ReadValue(); //this code works
buttonPressed = controller.testAction.action.ReadValue(); //this code doesnt, can't find testActions
if(buttonPressed == true)
{
Debug.Log("Button Pressed");
}
}
}
Nice Tut.
Is there a way to control the XR Rig via Android Smartphone?
I tried to use:
device rotation[HandheldARInputDevice]
device rotation[OpenVR Headset]
attitude[Sensor]
But via Unity Remote 5 nothing happens.
Do I have to set up my device differently?
Running the API also doesnt work. And anyway the workflow is too slow to test it like that.
How do you detect button presses? Like the X and Y buttons on the oculus quest controllers for example?
That would be the Primary or Secondary button inputs for the Generic Controller. But, if you're using OpenXR you can access the inputs on a per controller basis if you want to be more specific.
@@VRwithAndrew Is there an easy way to change what those buttons do depending on other things? Like if you're holding something the primary button does one thing, but if you're holding something different it does something else?
I updated the XR Interaction Toolkit to import the Default Input Action. However, as soon as I imported it, I saw the function [protected void OnSelectEnter (XRBaseinteractor)] part of Interactables' AxisDragInteractable.cs error occurred. I want to ask if there is a solution.
It is said that no suitable method was found to override.
@@user-wt1oq2fx8r When you're using updated version of XR Toolkit, they've updated to use EventArguments. I cover this at the beginning of my Bow and Arrow 2.0 video.
I was having issues making code run when the primaryButton on the right controller was pressed. After a real long time messing with this I was able to get it working, wanted to share in case someone else was having this issue. First, go double click your XRI Default Input Actions asset. Click XRI RightHand in the left column, and then click the + symbol in the middle column to create your action. I named mine Test, click it and set the Action Type in the right colum to button, then click the + symbol next to Test and click Add Binding. Click the new binding, and then in the path parameter in the right column navigate to the primaryButton for the XR controllers, check the "Generic XR Controller" checkbox. Once the Test action is created in the input action window you have to add it to the ActionBasedController script, this is what was throwing me off. Open that script and add the following, this will allow you to reference the Test action in other scripts:
[SerializeField]
InputActionProperty m_TestAction;
public InputActionProperty testAction
{
get => m_TestAction;
set => SetInputActionProperty(ref m_TestAction, value);
}
Once you have done that you can reference this action in code. The buttons are weird with this system btw too, the button press will return a float and not a bool like you would think. To make something happen when the button is pressed do if (buttonPressed > 0) instead of if(buttonPressed == true), you could also create a function and have it run when the button is triggered here is the code I used:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR.Interaction.Toolkit;
public class ActionInputTest : MonoBehaviour
{
private float buttonPressed; //bool that stores true or false if button is pressed
private ActionBasedController controller;
private void Start()
{
controller = GetComponent();
}
void Update()
{
buttonPressed = controller.testAction.action.ReadValue();
if (buttonPressed > 0)
{
Debug.Log("Button Pressed");
}
}
}
If you're simply trying to read the value, you don't have include it in the controller. Also, the scripts that are included in Packages aren't saved between Unity re-loads. You can very well do the same thing using this script.
github.com/C-Through/XR-OpenXR/blob/main/Assets/_OpenXR/Scripts/AssetInputExample.cs
@@VRwithAndrew Hi Andrew, sorry I'm not sure what you are explaining with this script. Are you stating that I don't need to alter the ActionBasedController using the script you provided? And yes, just simply trying to tell if the primaryButton on the right hand is pushed, and if it gets pushed run some code. I'm still not understanding how the script you provided would allow me to access an action I create called Test. I'm honestly finding all of this new system very confusing though the scripting part anyway so it's probably just not making sense to me. I get the concept, like setting up actions and then writing code to act off of the action instead of a specific controller so it can be easily reconfigured, but the coding required to do something as simple as telling if a button is pressed pretty just makes it a headache.
@@flurishart612 If you watch the OpenXR video. I show how to use it. You may need to look into some more generic Input System videos.
@@VRwithAndrew ok thx
@@VRwithAndrew I think I get what you are saying now thx. Instead of adding the testAction to your controller, you could just create a script and then declare a public InputActionReference variable named test for example, and then drag the testAction from the asset window in that, and then just do buttonPressed = test.action.ReadValue(); to read the value, or do the test.action.started or performed if you just want something to happen when the button is pressed. Sounds like you could do action.ReadValue in an update function or use action.performed from a start function in your doPerformedThing example, is one method better than the other or is there a difference I'm not understanding? thx
How can i read the buttons values from a script?
If you look into more generic Input System videos, they should show you how to use the ReadValue function. I touch on it at the end of my OpenXR video.
Is there a tldr on how to setup a new action? I'm trying to subscribe to a primary button action, set it up in the action menu and mapped it to generic XR left hand. How can I access this in code to subscribe to the event, though?
If you look into my OpenXR video/template project there is an example there for subscribing to an input's events.
so there's a rotation "action" but how do you actually get the rotation out of it ? the only parameter is a callback:
controller.rotationAction.action.performed += (UnityEngine.InputSystem.InputAction.CallbackContext obj) => { };
You can actually poll actions: docs.unity.cn/Packages/com.unity.inputsystem@1.0/manual/Actions.html#polling-actions
@@pohyart This is correct, you can use the ReadVaue method.
how to actually link the actions in XR Controller (6:30) to methods?
All of those actions are set up to select, activate, and all that. If you're trying to do additional actions for the XR Controller, it's possible but overly in-depth to do. I do cover more customization for actions in my Custom XR Actions video.
How do I use this if I want a debug.log when I press A,B X or Y on my Quest2? Do you have a script for that? Been searching for this info the past 4 days, can't move on until I know how.
I'm putting together a simple project on this since it's a very common question. In the meantime, I would recommend looking into more generic Input System videos, and my OpenXR video. It has some info on input as well.
@@VRwithAndrew Fantastic! Looking forward to watching it ! :)
Hey man i just wanted to know if it possible to create a spectator camera inside a vr scene with unity xr input management. I wanted to make a controlable spectator camera with mouse and keyboard but the xr input wont let me
In theory, I think you'd be able to do it. If you can get the camera and everything setup correctly. You may need to look into how the Input System handles multiplayer. Or, you may be able to get away with writing your own script to Activate all of the actions, and have the functionality you want hooked up to them. You can see more of that here.
docs.unity3d.com/Packages/com.unity.inputsystem@0.2/manual/Actions.html
@@VRwithAndrew thanks alot man! At the moment the xr input is disabling my camera control script and mouse input, need to find a way around it
I'm running into a problem with the action-based XR rig. I'm on an Oculus Quest 2 in Unity 2020.2. When I build and run, the scene is locked in one position. Moving my head does nothing. My controllers are also locked onto the headset's position. As a check, I ran Unity's example VR scene and had no problems on my headset. I've tried everything I can think of: building in a fresh version of Unity, building in the URP instead of 3D, and double-checking the project settings. I also deselected everything in the Unity example scene and rebuilt the room-scale action-based XR rig in there, and it worked. I must be missing a setting somewhere, but I don't know what it is. Does anyone have any idea what might be causing this, and how to fix it?
Update: I figured out the problem, sort of. If I run through the above tutorial in 2019.4, everything works. Then, if I reopen the project as a 2020.2 project, it works there as well. Unity does something in the background to update the project, not sure what but it works.
@@peterweigel2991 I was able to solve this problem by following the advice here: forum.unity.com/threads/xr-interaction-toolkit-0-10-preview-is-available.1000576/#post-6497878. My problem was Active Input Handling was set to "Input Manager (old)" in Project Settings > Player.
How do you assign new actions to controls?
Everything gets funneled into the Select, and Activate via the XRController. If you're looking at more functionality, that's a bit of a process that I don't have a video on.
Have you figured out how to use this with XRGrabInteractables? i can't get onActivate to trigger, and the weapon I'm holding just rotates like it's inside of a microwave.
Ahaha, what controller are you using?
@@VRwithAndrew I have since figured it out. It was rotating because that's what the rotate anchor input does. I had to disable that. The trigger wasn't working because I'm a moron and I forgot that I had copied a scene (and didn't include it in the build).
Thanks for the reply 😄
If you'd like to know more about saving and apply presets check out this manual from Unity.
docs.unity3d.com/Manual/Presets.html
Thanks Andrew. I must be dumb, but wow for some reason I feel Unity is making everything somewhat more difficult. On one hand I feel getting input from controllers seems more straight forward and less (or zero) code, but on the other...there's something about how they're designing everything that makes it more annoying. Don't even get me started with ECS.
yea this is especially un-intuitive.
It's certainly not perfect. Unity is aware on how they've dropped the ball in some areas and trying to more transparent in the futre. The New Input System is very flexible and there are a lot of different ways of using it. However, the documentation is incredibly dense and it took me sometime to figure out how to do things. This is with my existing experience with Action-Based Input coming from SteamVR.
3:57
Unity have change the name from Default Input Actions to Starter Assets
I need to have complex inputs, such as a different 'activation' of a selected or grabbed object for different button press events like trigger vs A vs B vs B + trigger vs A+ etc... Also, I need to have a teleport function that activates whenever you move the analogue stick forward, disabling the grab function, but I need to stop it from triggering when the grab is triggered.... I'm getting a headache with this stuff, you think you could make a video that goes into a little more detail, with some variation, and maybe even a little peek into how the scripts do their thing?
Potentially! If I have a good example/use-case off an interactable or something benefiting from additional input. Others may find that useful.
@@VRwithAndrew for instance, in VR chat, many of the animations require multiple buttons being pressed in combination. sometimes this loads an animation, or swaps out the model of the object that hand is holding. some objects, because of their size, like a shield in a combat game, could block fast movement such as teleport. (conditional suppression of teleport) you might also want to trigger this when in combat, or in menus, etc.
sorry for the late reply, I didnt see the youtube notification somehow
oh, maybe you could make essentially a code template that would point to several of the 'actions' and change what button each action is tied to, disable and enable it, and tie it to a set named object being 'selected' or spicifically 'grabbed' or 'raycast selected' you could also show it being called by a external script to simulate game state changes.
this is not to forget showing a sampling of effects these buttons could trigger, such as changing the model or triggering a particle effect, and would be good to show an example of a custom action, looks like you can just add one in the menu using the plus button at the top, but some people might not notice that. i could become a muffin supplier next month if you did this, just to get access to the template. would make a nice video though.
Can you do hand-tracking with this? i.e. Quest 2
Not that I'm aware of, but maybe in the future. There are some pieces of documentation that additional input is possible. Right now it's exclusive to using OVR to my knowledge.
@@VRwithAndrew Thanks. I'll try again with OVR. I had difficulty getting the hands to move other rigidbodies. I added a sphere collider to each hand but the sphere appeared a meter away from the hand. Not sure where I went wrong.
@@VRwithAndrew Also, I think hand-tracking won't be viable for most tasks because it will never be able to handle occlusion with headset cameras alone.
nice to find this info but it's already outdated... everything changed so much since the time you made that video. It's unusable now...
ho, sorry, just jump to czcams.com/video/5ZBkEYUyBWQ/video.html
But how do I bind a button to a custom function? I don't understand how to make the character sprint with the press of a button with this new system.
I have an additional video on this, "Custom Input Actions for Unity XR."
@@VRwithAndrew Thank you friend. I kept finding actual button game object videos when searching for how to bind buttons.
Thank you so much man!
You're welcome, Rodrigo!