How to Setup XR Toolkit's Action-Based Input in Unity

Поділитися
Вставка
  • Опубліковано 14 лип 2024
  • Support my work, and get access to source code!
    / vrwithandrew
    In this video, we're going to be setting up the new Action-Based Input for Unity's XR Toolkit.

КОМЕНТАРІ • 166

  • @Colab-Film
    @Colab-Film 3 роки тому +4

    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.

  • @WilkoGRACZ
    @WilkoGRACZ 3 роки тому +9

    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! :)

  • @c0d3_m0nk3y
    @c0d3_m0nk3y Рік тому

    This is one of the most helpful Unity tutorials, I have ever seen! Thank you so much!

  • @CitizenPurpelios
    @CitizenPurpelios 3 роки тому +12

    amazing that you posted this today I JUST needed this.

  • @cedricknapp2889
    @cedricknapp2889 3 роки тому

    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! :)

  • @genemedicd
    @genemedicd 2 роки тому +1

    Pure gold! I was having so much trouble and I was missing adding the Input Action Manager script. Thanks so much!

  • @mewing55
    @mewing55 3 роки тому +1

    extremely helpful tutorial. combines a lot of info in a short time. great work!

  • @valentinsourice3780
    @valentinsourice3780 3 роки тому +3

    This is gold, thanks for keeping us up to date

  • @vitnovak
    @vitnovak 3 роки тому

    O M G! You actually go to the documentation and explain all the "whys"! This is so awesome!

  • @davidblissett5315
    @davidblissett5315 3 роки тому

    Thanks for showing us the way Man. Such great content. Really appreciated.

  • @colincreamer
    @colincreamer 3 роки тому

    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!

  • @johnjohnhenry7645
    @johnjohnhenry7645 3 роки тому

    GENIUS !!! I spent two days trying to understand that !

  • @petacrdi
    @petacrdi 2 роки тому

    Oh, man, thank you! I was missing the Input Action Manager. Great channel, very useful for beginners like me.

  • @CastleBomber
    @CastleBomber 7 місяців тому +1

    dope! got through a hurdle, thanks man

  • @NightSpyderTech
    @NightSpyderTech 3 роки тому

    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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      Aren't we all! I'm glad we're finally getting a more straightforward solution.

  • @Diablokiller999
    @Diablokiller999 3 роки тому +1

    So this is how it works, didn't get my head around it for the last few days, thank you so much! :)

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      Glad it helped!

    • @VeryDavidChannel
      @VeryDavidChannel 3 роки тому +1

      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!

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому +1

      @@VeryDavidChannel Yep! This can also be found in the Presets Documentation that a pinned.

  • @frozensmoketrails
    @frozensmoketrails 3 роки тому

    Thank you for this video!!
    This is stuff that should be in the official docs to begin with.

  • @pratiklohokare8591
    @pratiklohokare8591 2 роки тому

    thank you so much bro, for this detailing

  • @IProKv
    @IProKv 3 роки тому

    THANK YOU ANDREW YOU LOOK AFTER US HOMIE, DIVINES BLESS YOU MY MAN

  • @PhillipsAlbright
    @PhillipsAlbright 2 роки тому

    great explanation of this system, even after two years.

  • @igorwidawski842
    @igorwidawski842 2 роки тому

    Thank you Andrew! Your video has saved me a lot of time! :)

  • @coatube
    @coatube 3 роки тому

    best tutorial for biginner of xr toolkits . very awesome!

  • @hernandonj
    @hernandonj 2 роки тому

    Great video. Thanks!

  • @citywizardgames
    @citywizardgames Рік тому

    You're my hero, I was beating my head against the terrible default Unity instructions on this all week. Cheers man.

  • @JamesWjRose
    @JamesWjRose 3 роки тому

    Thank you very much for this, very helpful.

  • @HRezakhani
    @HRezakhani 3 роки тому

    Thanks, it helps me a lot.

  • @ourybah7633
    @ourybah7633 3 роки тому

    Thank you!

  • @adhochero6619
    @adhochero6619 3 роки тому +1

    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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому +1

      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

  • @WTGDarksight
    @WTGDarksight 3 роки тому

    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

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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.

  • @Xzarations
    @Xzarations 3 роки тому

    Awesome!

  • @dimensional7915
    @dimensional7915 3 роки тому

    now this is what we call progress

  • @marekrimal2371
    @marekrimal2371 2 роки тому

    Briliant

  • @dustinmilotte8852
    @dustinmilotte8852 3 роки тому +1

    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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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.

  • @joel352
    @joel352 3 роки тому

    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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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.

  • @Grezebhr
    @Grezebhr 3 роки тому

    JEEZ! THANKS

  • @ELPIRATATUQUE
    @ELPIRATATUQUE 2 роки тому

    Awesome, Would like to use movement with Actionbased XR, any vids?

    • @AndrewMakingAnything
      @AndrewMakingAnything  2 роки тому

      Not exactly, but I do have this video that shows how to implement XR Toolkit's built-in locomotion.
      ua-cam.com/video/4WiMogkep1U/v-deo.html

  • @flurishart612
    @flurishart612 3 роки тому

    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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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.

    • @flurishart612
      @flurishart612 3 роки тому

      @@AndrewMakingAnything 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?

    • @flurishart612
      @flurishart612 3 роки тому

      @@AndrewMakingAnything 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();

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      @@flurishart612 Depending upon how to have the action setup, you may want to try reading it as a float.

    • @flurishart612
      @flurishart612 3 роки тому

      @@AndrewMakingAnything 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");
      }
      }
      }

  • @imdixon8108
    @imdixon8108 3 роки тому

    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?

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      If you look into my OpenXR video/template project there is an example there for subscribing to an input's events.

  • @ikramandaliff
    @ikramandaliff 3 роки тому

    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

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому +1

      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

    • @ikramandaliff
      @ikramandaliff 3 роки тому

      @@AndrewMakingAnything 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

  • @josemartins-game
    @josemartins-game 2 місяці тому

    Interesting. But how do we actually read the controller buttons ? Example A and B buttons on a meta quest controller ?

  • @javhus
    @javhus 3 роки тому

    How do you detect button presses? Like the X and Y buttons on the oculus quest controllers for example?

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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.

    • @exof8824
      @exof8824 2 роки тому

      @@AndrewMakingAnything 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?

  • @KipppJ
    @KipppJ 3 роки тому

    Based.

  • @FPChris
    @FPChris 3 роки тому

    Do you change the Main Camera's position on it's transform or the Camera Offset's transform? Thx

  • @Xzarations
    @Xzarations 3 роки тому +4

    Does this support valve index controllers yet?

    • @DeGandalf
      @DeGandalf 3 роки тому

      I have the same question, it would be great if someone knew this.

    • @Xzarations
      @Xzarations 3 роки тому

      @@DeGandalf yeah I have been waiting for better index support for ages

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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.

    • @Xzarations
      @Xzarations 3 роки тому

      @@AndrewMakingAnything 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!

  • @WesleyOverdijk
    @WesleyOverdijk 3 роки тому

    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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому +1

      Ahaha, what controller are you using?

    • @WesleyOverdijk
      @WesleyOverdijk 3 роки тому

      @@AndrewMakingAnything 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 😄

  • @danielstrobel8369
    @danielstrobel8369 3 роки тому

    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?

    • @danielstrobel8369
      @danielstrobel8369 3 роки тому

      Running the API also doesnt work. And anyway the workflow is too slow to test it like that.

  • @user-wt1oq2fx8r
    @user-wt1oq2fx8r 3 роки тому

    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
      @user-wt1oq2fx8r 3 роки тому

      It is said that no suitable method was found to override.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      @@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.

  • @valentinsourice3780
    @valentinsourice3780 3 роки тому

    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;

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      You'll want to use the type "InputActionAsset" rather than "XRIDefaultInputActions".

    • @valentinsourice3780
      @valentinsourice3780 3 роки тому

      ​@@AndrewMakingAnything 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();

  • @egrinant2
    @egrinant2 3 роки тому

    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!!

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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?

    • @egrinant2
      @egrinant2 3 роки тому +1

      ​@@AndrewMakingAnything 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!

    • @akravatorwind8976
      @akravatorwind8976 3 роки тому

      @@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.

    • @egrinant2
      @egrinant2 3 роки тому

      @@akravatorwind8976 centerEyePosition [Oculus Headset] and centerEyeRotation [Oculus Headset]

    • @yohosuff
      @yohosuff 3 роки тому

      @@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.

  • @peterweigel2991
    @peterweigel2991 3 роки тому

    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?

    • @peterweigel2991
      @peterweigel2991 3 роки тому

      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.

    • @yohosuff
      @yohosuff 3 роки тому

      @@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.

  • @mboe94
    @mboe94 3 роки тому

    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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому +1

      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.

    • @mboe94
      @mboe94 3 роки тому

      @@AndrewMakingAnything Fantastic! Looking forward to watching it ! :)

  • @ownedge7329
    @ownedge7329 2 роки тому

    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" =(

    • @AndrewMakingAnything
      @AndrewMakingAnything  2 роки тому

      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.

    • @ownedge7329
      @ownedge7329 2 роки тому

      @@AndrewMakingAnything 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!)

  • @davidgarrett30
    @davidgarrett30 2 роки тому

    Currently trying to get a button click working and it isn't. A video on that would be sweet.

  • @Timotheeee1
    @Timotheeee1 3 роки тому

    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) => { };

    • @pohyart
      @pohyart 3 роки тому

      You can actually poll actions: docs.unity.cn/Packages/com.unity.inputsystem@1.0/manual/Actions.html#polling-actions

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      @@pohyart This is correct, you can use the ReadVaue method.

  • @PhillipsAlbright
    @PhillipsAlbright 2 роки тому

    How do you assign new actions to controls?

    • @AndrewMakingAnything
      @AndrewMakingAnything  2 роки тому

      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.

  • @mireazma
    @mireazma 2 роки тому

    how to actually link the actions in XR Controller (6:30) to methods?

    • @AndrewMakingAnything
      @AndrewMakingAnything  2 роки тому

      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.

  • @davidosorio1585
    @davidosorio1585 3 роки тому

    How can i read the buttons values from a script?

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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.

  • @rl1111rl
    @rl1111rl 3 роки тому

    Can you do hand-tracking with this? i.e. Quest 2

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому +1

      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.

    • @rl1111rl
      @rl1111rl 3 роки тому

      @@AndrewMakingAnything 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.

    • @rl1111rl
      @rl1111rl 3 роки тому

      @@AndrewMakingAnything 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.

  • @flurishart612
    @flurishart612 3 роки тому

    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");
    }
    }
    }

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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

    • @flurishart612
      @flurishart612 3 роки тому

      @@AndrewMakingAnything 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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      @@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.

    • @flurishart612
      @flurishart612 3 роки тому

      @@AndrewMakingAnything ok thx

    • @flurishart612
      @flurishart612 3 роки тому

      @@AndrewMakingAnything 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

  • @CJRH1FILMS
    @CJRH1FILMS 3 роки тому

    Right Click > XR > "Convert Main Camera to XR Rig" ... that is my only option. What am I doing wrong?

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      Double-check that you've added XR Toolkit from the Package Manager.

  • @sixsugarssixburners2318
    @sixsugarssixburners2318 3 роки тому

    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.

    • @KidGold17
      @KidGold17 3 роки тому +1

      yea this is especially un-intuitive.

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому

      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.

  • @markus6056
    @markus6056 2 роки тому

    3:57
    Unity have change the name from Default Input Actions to Starter Assets

  • @tenzenin6301
    @tenzenin6301 3 роки тому +1

    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?

    • @AndrewMakingAnything
      @AndrewMakingAnything  3 роки тому +1

      Potentially! If I have a good example/use-case off an interactable or something benefiting from additional input. Others may find that useful.

    • @tenzenin6301
      @tenzenin6301 3 роки тому

      @@AndrewMakingAnything 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.

    • @tenzenin6301
      @tenzenin6301 3 роки тому

      sorry for the late reply, I didnt see the youtube notification somehow

    • @tenzenin6301
      @tenzenin6301 3 роки тому

      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.

    • @tenzenin6301
      @tenzenin6301 3 роки тому

      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.

  • @AndrewMakingAnything
    @AndrewMakingAnything  3 роки тому

    If you'd like to know more about saving and apply presets check out this manual from Unity.
    docs.unity3d.com/Manual/Presets.html

  • @DominiqueLavault
    @DominiqueLavault Рік тому +1

    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...

    • @DominiqueLavault
      @DominiqueLavault Рік тому

      ho, sorry, just jump to ua-cam.com/video/5ZBkEYUyBWQ/v-deo.html

  • @Palatard
    @Palatard Рік тому

    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.

    • @AndrewMakingAnything
      @AndrewMakingAnything  Рік тому +1

      I have an additional video on this, "Custom Input Actions for Unity XR."

    • @Palatard
      @Palatard Рік тому

      @@AndrewMakingAnything Thank you friend. I kept finding actual button game object videos when searching for how to bind buttons.

  • @rodrigo.cs.machado
    @rodrigo.cs.machado 3 роки тому

    Thank you so much man!