Custom Grab Hand Pose with Unity XR Toolkit - PART 1

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024

ความคิดเห็น • 76

  • @xXYannuschXx
    @xXYannuschXx 9 หลายเดือนก่อน +6

    Really good tutorial, but I want to add two things I noticed:
    1) In the newer XRI Toolkit versions the DirectInteractor isnt part of the XRBaseController gameobject anymore, so "HandData handData = arg.interactorObject.transform.GetComponentInChildren(); " wont work anymore. You either need to use GetComponentInParent() or use the following code:
    if (args.interactorObject is XRBaseControllerInteractor controllerInteractor && controllerInteractor != null)
    {
    var controller = controllerInteractor.xrController.transform.GetComponentInChildren();
    }
    2) If you have moved the DirectInteractor around, the hand will get moved to a wrong position; I solved this by passing the transform of the DirectInteractor to the SetHandDataValues method and adding the localPosition (divided by localScale just in case) to the finalHandPosition.

  • @RigidDecay
    @RigidDecay 2 ปีที่แล้ว +4

    Thanks so much valem, this is a very needed tutorial. Crazy how high quality these are.

    • @ValemVR
      @ValemVR 2 ปีที่แล้ว +5

      Thank you I'm trying my best to bring the best quality content for vr dev ! It means a lot that it is noticeable by some people like you. :D

    • @francopanigaia2425
      @francopanigaia2425 2 ปีที่แล้ว

      @@ValemVR yes thanks for the amazing content!

  • @JoelB71
    @JoelB71 ปีที่แล้ว +1

    Bravo! Another super dense tutorial packed with useful information. So good!

  • @brandonprescotthabibicompi8384
    @brandonprescotthabibicompi8384 2 ปีที่แล้ว +6

    Great tutorial as always, very helpful. Will you do one on making reloading (like, pulling the pistol slide), or will the old one still work with the scripts used in this one? :D Thanks!

  • @NickTugarin
    @NickTugarin ปีที่แล้ว

    Dude your tutorials are so saving so much time, thank you!

  • @jussi81
    @jussi81 ปีที่แล้ว +2

    EDIT: Its fixed! In one of the previous episodes we made XRGrabInteractable script, and later it was replaced with XRGrabInteractableTwoAttach script. I didn't remove it, I just disabled it since I though its the same thing. Now when I removed it everything works! Maybe GetComponent found the old version that wasn't used?
    I can't get this to work, and reason is it never goes anywhere from Start(). I wonder why AddListener doesn't work? I have checked typos and added Debug.Logs, and according to them I only go to Start(), debugs tell me the name of the grabInteractable, so it finds XRGrabInteractable. Only thing different is that I have my own pistol model, but that has worked correctly in whole tutorial serie.

    • @jussi81
      @jussi81 ปีที่แล้ว

      FIXED!!!! :;D

    • @kopsone3898
      @kopsone3898 ปีที่แล้ว +1

      @@jussi81 could you post your script here? i have problems with the XRGrabInteractableTwoAttach script it just gives me errors...

  • @lin_vitamin
    @lin_vitamin ปีที่แล้ว +10

    Grab Hand Pose script:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.XR.Interaction.Toolkit;
    public class GrabHandPose : MonoBehaviour
    {
    public HandData rightHandPose;
    private Vector3 startingHandPosition;
    private Vector3 finalHandPosition;
    private Quaternion startingHandRotation;
    private Quaternion finalHandRotation;
    private Quaternion[] startingFingerRotations;
    private Quaternion[] finalFingerRotations;
    void Start()
    {
    XRGrabInteractable grabInteractable = GetComponent();
    grabInteractable.selectEntered.AddListener(SetupPose);
    grabInteractable.selectExited.AddListener(UnSetPose);
    rightHandPose.gameObject.SetActive(false);
    }
    public void SetupPose(BaseInteractionEventArgs arg)
    {
    if(arg.interactorObject is XRDirectInteractor)
    {
    HandData handData = arg.interactorObject.transform.GetComponentInChildren();
    handData.animator.enabled = false;
    SetHandDataValues(handData, rightHandPose);
    SendHandData(handData, finalHandPosition, finalHandRotation, finalFingerRotations);
    }
    }
    public void UnSetPose(BaseInteractionEventArgs arg)
    {
    if (arg.interactorObject is XRDirectInteractor)
    {
    HandData handData = arg.interactorObject.transform.GetComponentInChildren();
    handData.animator.enabled = true;
    SendHandData(handData, startingHandPosition, startingHandRotation, startingFingerRotations);
    }
    }
    public void SetHandDataValues(HandData h1, HandData h2)
    {
    startingHandPosition = new Vector3(h1.root.localPosition.x / h1.root.localScale.x,
    h1.root.localPosition.y / h1.root.localScale.y, h1.root.localPosition.z / h1.root.localScale.z);
    finalHandPosition = new Vector3(h2.root.localPosition.x / h2.root.localScale.x,
    h2.root.localPosition.y / h2.root.localScale.y, h2.root.localPosition.z / h2.root.localScale.z);

    startingHandRotation = h1.root.localRotation;
    finalHandRotation = h2.root.localRotation;
    startingFingerRotations = new Quaternion[h1.fingerBones.Length];
    finalFingerRotations = new Quaternion[h1.fingerBones.Length];
    for (int i = 0; i < h1.fingerBones.Length; i++)
    {
    startingFingerRotations[i] = h1.fingerBones[i].localRotation;
    finalFingerRotations[i] = h2.fingerBones[i].localRotation;
    }
    }
    public void SendHandData(HandData h, Vector3 newPosition, Quaternion newRotation, Quaternion[] newBonesRotation)
    {
    h.root.localPosition = newPosition;
    h.root.localRotation = newRotation;
    for (int i = 0; i < newBonesRotation.Length; i++)
    {
    h.fingerBones[i].localRotation = newBonesRotation[i];
    }
    }
    }

    • @Blockington
      @Blockington ปีที่แล้ว +1

      thank you so much you just saved me too much time

    • @RajkumarV-pb8qk
      @RajkumarV-pb8qk ปีที่แล้ว +1

      Mee too man, I didn't know where I got error in code, but you just saved a lot of time for me!!

    • @WhatWhatWHAT233
      @WhatWhatWHAT233 4 หลายเดือนก่อน

      i didn't know what was wrong with my one but thank you you saved me a lot of time

    • @lzmkalos
      @lzmkalos 3 หลายเดือนก่อน

      Really thx you!

  • @TheAniMateChannel
    @TheAniMateChannel 6 หลายเดือนก่อน

    You can fix the pistol scale issues by going to the pistol folder and changing the import scale to 4 there. Then you can have the pistol scaled to 1 in Inspector so the hands are correctly scaled from the start.

  • @mimizuX
    @mimizuX 2 ปีที่แล้ว

    Oh, man, this is a present! Thanks a lot!

  • @Twistashio
    @Twistashio 2 ปีที่แล้ว

    I would love a tutorial on a physic button with unity XR if possible. Been a life saver for getting started with vr!

  • @berkunal390
    @berkunal390 ปีที่แล้ว

    this is wonderful copy from steamvr plugin :D I was thinking to create the same and then I found this video

  • @francopanigaia2425
    @francopanigaia2425 2 ปีที่แล้ว +1

    I love to see this series progressing further!!!! wow!!!!!

  • @eliashaug4324
    @eliashaug4324 2 ปีที่แล้ว +3

    Great tutorial as always!, i an trying to make a VR game myself and its going pretty well! my only problem is the enemy. Could you cover how to create active ragdoll balance, stabbing, etc. Pretty much a full simple enemy. Love your content and see you around! :)

    • @ValemVR
      @ValemVR 2 ปีที่แล้ว +1

      Thanks for the comment ! :D I made a tutorial on my patreon about remaking superhot in 2 hours. It covers some pretty cool enemy like pathway AI, hitting with fist, making the enemy shoot at you, make the enemy hittable and so on. :)

    • @eliashaug4324
      @eliashaug4324 ปีที่แล้ว

      @@ValemVR Ohh! Thank you so much. I sadly can't get the patreon just now because of a couple reasons but when i can i will check it out 100% :)

  • @jovan_spasovic
    @jovan_spasovic 2 ปีที่แล้ว +3

    Thank you so much! Is it possible to program an automatic hand poser? It seems unrealistic to me that every company creating a VR game has to animate a hand pose for each in game item, as some games have many interactable items, like Boneworks.

  • @KeshaBagadia
    @KeshaBagadia 5 หลายเดือนก่อน +1

    for some reason, my xr grab interctable component doesn't have separate left and right attach points :')

  • @smixii5233
    @smixii5233 2 ปีที่แล้ว +1

    Now do tutorial on saving system that saves( like instance saving, load and you spawn back to what you had before) Player position and other items spawned by player that was bought through a shop menu that you added off video 👍

    • @Need2pee
      @Need2pee ปีที่แล้ว

      You can use class streamwriter and streamreader for that along with json to write a class or stuct into a text file then read it back into your c# code it's very simple check out videos for that

  • @loosefootgoose919
    @loosefootgoose919 2 ปีที่แล้ว

    Legend, thanks Valem

  • @vargasxr421
    @vargasxr421 ปีที่แล้ว

    So Good! Valem!

  • @viva-la-baz1458
    @viva-la-baz1458 7 หลายเดือนก่อน +1

    Followed all tutorials to this one, but when grabbing the gun the hand does not change pose for me at all.

  • @capitaljay1
    @capitaljay1 ปีที่แล้ว

    I wish I saw this tutorial before I built out to my quest and then went back and adjusted in build out to my quest and then went back and adjusted and then went back and built to my quest to go back and adjust some more

  • @pastuh
    @pastuh ปีที่แล้ว +1

    Nice video :)
    I wonder how we could animate the weapon grab if the weapon was on a rope or only the handle was visible.

  • @3d-action
    @3d-action ปีที่แล้ว +4

    HandData code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class HandData : MonoBehaviour
    {
    public enum HandModelType { Left, Right}

    public HandModelType handType;
    public Transform root;
    public Animator animator;
    public Transform[] fingerBones;
    }

    • @Fish_SmileyFace
      @Fish_SmileyFace ปีที่แล้ว

      not much time saved but you helped :)

  • @jakehobbs6821
    @jakehobbs6821 ปีที่แล้ว +1

    I can't for the life of me get the interactor to move to the posed hands position/rotation at all. The grabbable just wants to move to the default Attach Transform on the XR Director Interactor (and if there isn't one, it spawns one) no matter what... What am I missing? D:

  • @prohot9695
    @prohot9695 ปีที่แล้ว +1

    When you first set up the hand and its suppose to freeze it wont do that for me.
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.XR.Interaction.Toolkit;
    public class GrabHandPose : MonoBehaviour
    {
    public HandData rightHandPose;
    void Start()
    {
    XRGrabInteractable grabInteractable = GetComponent();
    grabInteractable.selectEntered.AddListener(SetupPose);
    rightHandPose.gameObject.SetActive(false);
    }
    public void SetupPose(BaseInteractionEventArgs arg)
    {
    if(arg.interactorObject is XRDirectInteractor)
    {
    HandData handData = arg.interactorObject.transform.GetComponentInChildren();
    handData.animator.enabled = false;
    }
    }
    }
    No idea why it will not work. I am also getting this error ArgumentException: Object of type 'UnityEngine.Object' cannot be converted to type 'UnityEngine.Transform'.
    System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) and it just goes on and on about something in the XRI code.

  • @toastedclosure2770
    @toastedclosure2770 4 หลายเดือนก่อน

    i have an issue, if a controller is on, the item disappears, but if the controller's off, it spawns where i put the item with the hand
    edit: i have no idea what i did, but i made them appear now, but the pose doesnt work for some reason, im also getting the error of a nullreference that HandData component not found in the children of the interactor object.

  • @awesomenesswithisaac3509
    @awesomenesswithisaac3509 3 หลายเดือนก่อน

    As soon as I did the final offset fix, I got like 5 errors on the script and I have no clue how to fix them

  • @maokruDev
    @maokruDev 9 หลายเดือนก่อน

    Hi Valem! Would this tutorial work with the XR Hands? Or is there another option to create custom grabs for hand tracking using the XR Hands :0

  • @rosx_8446
    @rosx_8446 2 ปีที่แล้ว

    FINALLY!!!!

  • @chowwill9828
    @chowwill9828 ปีที่แล้ว +1

    Boss,Can you provide an tutorial of how to hold a long gun like AK47 with both hands and put it back to the chest? I always have trouble with it.

    • @dantheman3825
      @dantheman3825 7 หลายเดือนก่อน

      @chowwill9828 Same, Have you found a solution yet?

  • @ChrisBurns3D
    @ChrisBurns3D ปีที่แล้ว +2

    80% of the time it works for me. Anyone else getting that? Its replicateable if you grab the gun from the side, it's like it sometimes uses a different offset :/

  • @calland36
    @calland36 ปีที่แล้ว

    Edit: Found my issue. In the HandData script I forgot to update the "Hand Type" value properly to Right. It was set to Left for both hands, and it was causing a bunch of random issues. Check those values people! :D
    Hello Thank you for the video, I made it to the end and everything works where it gets my hand pose, but only the first time I grab the gun. When I grab it a second time or more, it defaults to the old grab pose. I was curious if this has to do with the fact we write all our code in the Start() function, and not update, so it only checks once? I'm unsure as I'm still learning here.
    Anyone have an idea on why it may do this?

  • @JandTubers
    @JandTubers ปีที่แล้ว

    Hi Valem! Nice tutorial as always! I have an issue... This method makes the player's hands move to an offset, I tried and I think it'd be better to snap the object instead, since it can cause a quite disturbing effect if the offset is large. Is it right or am I missing something?

  • @Meep-lm2jk
    @Meep-lm2jk ปีที่แล้ว

    hey valem is this going to work for multiple hand poses or 2 hands at one time

  • @LarryJunior334
    @LarryJunior334 6 หลายเดือนก่อน

    will this work for full bodies from that new tutorial?

  • @vishwas9778
    @vishwas9778 2 ปีที่แล้ว

    Hey, by any chance do you know the specs for the Quest 2 external cameras that are used for handtracking?

  • @paloma_1174
    @paloma_1174 ปีที่แล้ว

    How would I need to change the code so that this works with XR Ray Interactor? (and not only direct interactor)

  • @RoreosNFishnets
    @RoreosNFishnets 8 หลายเดือนก่อน

    How can you do this with the 3D model you used in your IK rigging video?

  • @Meep-lm2jk
    @Meep-lm2jk ปีที่แล้ว

    im using the vr template with the grab already setup and i dont know if thats what screwing it up

  • @Blockington
    @Blockington ปีที่แล้ว

    the grab hand data pose script never worked i looked over the script multiply times and I cant find any errors

  • @VLTNO
    @VLTNO 2 ปีที่แล้ว

    Hey Valem, I'm getting the "NullReferenceException: Object reference not set to an instance of an object" error on line 25 of the code.
    Here's the code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.XR.Interaction.Toolkit;
    public class GrabHandPose : MonoBehaviour
    {
    public HandData rightHandPose;
    void Start()
    {
    XRGrabInteractable grabInteractable = GetComponent();
    grabInteractable.selectEntered.AddListener(SetupPose);
    rightHandPose.gameObject.SetActive(false);
    }
    public void SetupPose(BaseInteractionEventArgs args)
    {
    if(args.interactorObject is XRDirectInteractor)
    {
    HandData handData = args.interactorObject.transform.GetComponent();
    handData.animator.enabled = false;
    }
    }
    }

    • @ValemTutorials
      @ValemTutorials  2 ปีที่แล้ว +1

      Yes you need to get the component in children with HandData handData = args.interactorObject.transform.GetComponentInChildren();
      and not HandData handData = args.interactorObject.transform.GetComponent();
      This is a mistake I made myself but I fixed it at 9:27

    • @VLTNO
      @VLTNO 2 ปีที่แล้ว +2

      @@ValemTutorials Thank you! Sorry for not looking ahead in the video.
      I normally just stop when something goes wrong and try to fix it.

  • @braileveracruz
    @braileveracruz 2 ปีที่แล้ว

    Is there a way to add jumping in VR?

  • @martinradner4542
    @martinradner4542 ปีที่แล้ว

    How did you get the "XR Grab Interactable Two Attach" I dont have it.

    • @federob3243
      @federob3243 ปีที่แล้ว

      i think that he made it in another video

    • @federob3243
      @federob3243 ปีที่แล้ว

      yes this one th-cam.com/video/nowlPXuPEG8/w-d-xo.html

    • @WhatWhatWHAT233
      @WhatWhatWHAT233 3 หลายเดือนก่อน

      yeah he made it in another video earlier in the series

  • @pulses0978
    @pulses0978 2 ปีที่แล้ว

    hey valem the hand is not disappering for me and i can not understand why could you help me

    • @RigidDecay
      @RigidDecay 2 ปีที่แล้ว

      did you watch the whole video

    • @pulses0978
      @pulses0978 ปีที่แล้ว

      @@RigidDecay muost of it yes, il watch it again to see oif i missed somthing

  • @karolledzinski710
    @karolledzinski710 9 หลายเดือนก่อน

    Must be another way becouse this script is not in optimise... 😅 It will be cpu power consuming.

  • @robatwarrior3591
    @robatwarrior3591 7 หลายเดือนก่อน

    bruh the grabhandpose script does not work 😭😭😭😭😭😭

  • @mtoon0
    @mtoon0 2 ปีที่แล้ว +1

    je crois reconnaitre l'accent mais je suis pas sur

  • @mattdway
    @mattdway ปีที่แล้ว

    Hi, I am trying to get this grab hand pose system to work in a project with the physical hands with non-physical hands set up from Valem's Tutorials (here: th-cam.com/video/VG8hLKyTiJQ/w-d-xo.html and here: th-cam.com/video/CfzO6jvLY-w/w-d-xo.html)
    There are no compile errors in my HandData or GrabHandPose scripts and I've combed through the code (comparing side by side with Quentin's source code, to make sure that everything matches his.
    In play testing, when I go to pick up a game object that has a posed right and left hand, those posed hands are never reactivated.
    As a test, I tried copying and pasting Quentin's GrabHandPose source code into my GrabHandPose script and play testing, and the same problem occurred, which makes me wonder if it is a problem in the structure or set up in the Unity Editor itself and not a logic error in the code? Using Debug.Log statements I can see that I am entering the SetupPose and SetHandDataValues methods.
    I also know from Debug.Logs that my interactable is my physical left-hand or right-hand controller and that from there it is finding the HandData component of the child, which is then my right or left physical hand.
    If anyone had any thoughts or suggestions for me, I'd be grateful! Or if anyone has gotten this pose system to work with the physical hand setup, I'd love to know if you have any tips or tricks to get this working. I'd love to try and get this grab pose system working in my own project, in the next day or two.
    Thank you!
    -Matt- :-)

  • @Noah-sw5xw
    @Noah-sw5xw 2 ปีที่แล้ว

    firsz

  • @evmdaily
    @evmdaily ปีที่แล้ว

    i get this error
    Assets\Scripts\GrabPose.cs(11,10): error CS0111: Type 'GrabPose' already defines a member called 'Start' with the same parameter types
    what did i do wrong?
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.XR.Interaction.Toolkit;
    public class GrabPose : MonoBehaviour
    {
    public HandData rightHandPose;

    // Start is called before the first frame update
    void Start()
    {
    XRGrabInteractable grabInteractable = GetComponent();
    grabInteractable.selectEntered.AddListener(SetupPose);
    rightHandPose.gameObject.SetActive(false);
    }
    public void SetupPose(BaseInteractionEventArgs arg)
    {
    if(arg.interactorObject is XRDirectInteractor)
    {
    HandData HandData = arg.interactorObject.transform.GetComponentInChildren();
    HandData.animator.enabled = false;
    }
    }
    }

    • @earth88_
      @earth88_ ปีที่แล้ว

      i asked chatGPT to fix it and this is what it sent, try and see if it works
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using UnityEngine.XR.Interaction.Toolkit;
      public class GrabPose : MonoBehaviour
      {
      public HandData rightHandPose;

      void Start()
      {
      XRGrabInteractable grabInteractable = GetComponent();
      grabInteractable.selectEntered.AddListener(SetupPose);
      rightHandPose.gameObject.SetActive(false);
      }
      public void SetupPose(BaseInteractionEventArgs arg)
      {
      if(arg.interactorObject is XRDirectInteractor)
      {
      HandData handData = arg.interactorObject.transform.GetComponentInChildren();
      handData.animator.enabled = false;
      }
      }
      }

  • @TheSateef
    @TheSateef ปีที่แล้ว +1

    awesome as ever, merci beaucoup. i cannot get
    HandData handData = arg.interactorObject.transform.GetComponentInChildren(); to work, it always returns null. and i have check the scripts and scene a hundred times. no idea what i'm doing wronf. so i cheated a bit and did this
    public void SetupPose(BaseInteractionEventArgs arg)
    {
    if (arg.interactorObject is XRDirectInteractor)
    {
    defaultRightHand.gameObject.SetActive(false);
    rightHandPose.gameObject.SetActive(true);
    }
    where defaultRightHand is a public that is set in the inspector draging the right hand model in the camera rig
    also need to add a way out like this
    public void LeaveSetupPose(BaseInteractionEventArgs arg)
    {
    Debug.Log("SetupPose LeaveSetupPose");
    defaultRightHand.gameObject.SetActive(true);
    rightHandPose.gameObject.SetActive(false);
    }
    use grabInteractable.selectExited.AddListener(LeaveSetupPose); to add a listener

    • @Truksama
      @Truksama ปีที่แล้ว

      @TheSateef, your comment helped me debug the same issue. So I wanted to make an account to tell you what I did. Thank you.
      What I did to resolve the issue is, in the GrabHandPose.cs script do:
      defaultRightHand.GetComponentInChildren();
      defaultRightHand.animator.enabled = false;
      SetHandDataValues(defaultRightHand,rightHandPose );
      SendHandData(defaultRightHand, finalHandPosition, finalHandRotation, finalFingerRotations);
      Do the same for your "LeaveSetupPose" except enable animation.
      I am using Interaction Toolkit 2.4.3 "XR Interaction Setup", so in Unity editor my Right Hand Model is a child of Right Controller. In inspector view of Right Controller, "XR Controller (Action-based)", add the default hand model to the "Model" and remove the "Model Prefab" and "Model Parent" association.
      If you do above, you will no longer need to use .SetActive() inside SetupPose and LeaveSetupPose.

    • @xXYannuschXx
      @xXYannuschXx 9 หลายเดือนก่อน +1

      @@Truksama The problem is that in the newer XRI Toolkits the DirectInteractor isnt on the same gameobject as the XRBaseController.
      You got two options: use GetComponentInParent() or the following:
      if (args.interactorObject is XRBaseControllerInteractor controllerInteractor && controllerInteractor != null)
      {
      var controller = controllerInteractor.xrController.transform.GetComponentInChildren();
      }
      "xrController" in this case is the XRBaseController the DirectInteractor is attached to; this is faster then using GetComponentInParent(), since it only uses a reference.