Search Unity

Feature Request Control XRGrabInteractable TargetLocalScale

Discussion in 'XR Interaction Toolkit and Input' started by chadrad, Feb 10, 2023.

  1. chadrad

    chadrad

    Joined:
    Aug 16, 2022
    Posts:
    1


    I am trying to create an XRPocketInteractor, similar to the pockets in Half-Life Alyx. However, when an XRGrabInteractable is grabbed it stored a target local scale and forces a scale when tracking. This prevents me from tweening the scale as it enters the pocket. I tried tweening that attach point, but as the socketed interactable is not a child it, the interactable does not scale.

    With that said, I would like the ability to have an Interactor modifies the selected interactable's target scale. I would imagine an API like
    Code (CSharp):
    1. float selectedInteractableScaleOverride
    that the XRGrabInteractable would query.
     
  2. mirobeka

    mirobeka

    Joined:
    Jun 14, 2020
    Posts:
    3
    I have exactly the same issue. Also if you try to use scale affordance system, to scale object when it's entering socket interactor, it snaps back to original scale. This doesn't make much sense.
     
  3. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    262
    One possible solution here is to put your mesh in a child game object and apply the scale affordance to that game object rather than the root object. That way both systems will touch different scale values and you should be able to get your desired result.
     
  4. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    To solve this issue I created a grab transformer which will drive the scale of an object to any desired value while the object is being interacted with.

    1. Create a grab transformer inheriting from XRBaseGrabTransformer

    2. Copy the following methods and code from XRSingleGrabFreeTransformer.cs

    public override void Process(XRGrabInteractable grabInteractable, XRInteractionUpdateOrder.UpdatePhase updatePhase, ref Pose targetPose, ref Vector3 localScale)

    And

    UpdateTarget(XRGrabInteractable grabInteractable, ref Pose targetPose, ref Vector3 localScale)

    3. Implement your own code to scale the object in an OnGrab override - you can check the grabInteractable in here to see which type of interactor (socket or hand) is selecting it, and apply whatever scale you want to the localScale variable in UpdateTarget()

    public override void OnGrab(XRGrabInteractable grabInteractable)
     
    Last edited: Mar 9, 2023
  5. vnmtsl

    vnmtsl

    Joined:
    Jul 13, 2020
    Posts:
    1
    changing the m_Target localScale from private to public or protected could solve the problem. Or a regular Boolean variable that turned on/off the record transform.localScale = m_Target localScale; And in the end you have to write crutches