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

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

Andrew

3 года назад

52,163 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

c0d3 m0nk3y
c0d3 m0nk3y - 12.07.2023 16:15

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

Ответить
Dan
Dan - 27.05.2023 11:14

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.

Ответить
Dominique Lavault
Dominique Lavault - 10.10.2022 21:16

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

Ответить
City Wizard Games
City Wizard Games - 08.10.2022 05:33

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

Ответить
Phillips Albright
Phillips Albright - 08.06.2022 23:23

How do you assign new actions to controls?

Ответить
Phillips Albright
Phillips Albright - 08.06.2022 23:22

great explanation of this system, even after two years.

Ответить
Igor Widawski
Igor Widawski - 25.12.2021 23:05

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

Ответить
Gene Villacian
Gene Villacian - 04.12.2021 10:51

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

Ответить
David Garrett
David Garrett - 23.11.2021 23:58

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

Ответить
reinaldo rodriguez
reinaldo rodriguez - 13.11.2021 04:16

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

Ответить
Hernando Nieto
Hernando Nieto - 21.10.2021 16:42

Great video. Thanks!

Ответить
Franco Sangiacomo
Franco Sangiacomo - 13.10.2021 23:44

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

Ответить
Marek Římal
Marek Římal - 06.10.2021 10:25

Briliant

Ответить
Pratik Lohokare
Pratik Lohokare - 01.10.2021 15:51

thank you so much bro, for this detailing

Ответить
Own Edge
Own Edge - 04.08.2021 14:51

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

Ответить
Kip
Kip - 27.07.2021 09:45

Based.

Ответить
Flying Notebook
Flying Notebook - 18.06.2021 09:49

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.

Ответить
Oury Bah
Oury Bah - 01.06.2021 03:48

Thank you!

Ответить
こぁ
こぁ - 28.05.2021 08:47

best tutorial for biginner of xr toolkits . very awesome!

Ответить
Sabin Timalsena
Sabin Timalsena - 27.05.2021 09:00

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

Ответить
CJ Rhone
CJ Rhone - 19.04.2021 00:36

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

Ответить
Vít Novák
Vít Novák - 15.04.2021 20:07

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

Ответить
Martin
Martin - 06.04.2021 17:26

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.

Ответить
rl1111rl
rl1111rl - 02.04.2021 18:40

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

Ответить
SoloTrail
SoloTrail - 31.03.2021 18:46

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

Ответить
Flurish Art
Flurish Art - 31.03.2021 08:48

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<ActionBasedController>();
}

void Update()
{
buttonPressed = controller.testAction.action.ReadValue<float>();

if (buttonPressed > 0)
{
Debug.Log("Button Pressed");
}
}
}

Ответить
Flurish Art
Flurish Art - 31.03.2021 00:05

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<bool>(); 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.

Ответить
Daniel Strobel
Daniel Strobel - 30.03.2021 16:30

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?

Ответить
cold streetdog
cold streetdog - 24.03.2021 14:36

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

Ответить
Michael Ewing
Michael Ewing - 14.03.2021 22:21

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

Ответить
Colin Creamer
Colin Creamer - 12.03.2021 04:55

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!

Ответить
Jan Schmieder
Jan Schmieder - 08.03.2021 12:18

JEEZ! THANKS

Ответить
David Osorio
David Osorio - 02.03.2021 04:42

How can i read the buttons values from a script?

Ответить
David Blissett
David Blissett - 27.02.2021 21:09

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

Ответить
Timotheeee1
Timotheeee1 - 20.02.2021 22:10

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

Ответить
FPChris
FPChris - 12.02.2021 19:58

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

Ответить
ImDixon
ImDixon - 08.02.2021 22:35

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?

Ответить
Hasan K. Rezakhani
Hasan K. Rezakhani - 01.02.2021 04:36

Thanks, it helps me a lot.

Ответить
Colab-Film
Colab-Film - 29.01.2021 19:11

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.

Ответить
Darksight
Darksight - 23.01.2021 20:14

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

Ответить
Peter Weigel
Peter Weigel - 16.01.2021 04:16

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?

Ответить
Joel
Joel - 16.01.2021 03:25

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.

Ответить
Dimensional
Dimensional - 15.01.2021 09:03

now this is what we call progress

Ответить
James Rose
James Rose - 12.01.2021 21:21

Thank you very much for this, very helpful.

Ответить
NightSpyder
NightSpyder - 01.01.2021 03:44

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.

Ответить
Dustin Milotte
Dustin Milotte - 27.12.2020 00:49

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.

Ответить
Edgar Griñant
Edgar Griñant - 24.12.2020 16:16

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

Ответить
Rodrigo Machado
Rodrigo Machado - 14.12.2020 15:59

Thank you so much man!

Ответить