Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Issues while extending Interactable

Discussion in 'XR Interaction Toolkit and Input' started by danUnity, Mar 26, 2021.

  1. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Hi,

    I'm currently extending some of the interactables (ARTranslationInteractable, ARScaleInteractable and ARRotationInteractable) so I duplicated them and I was thinking of just making some changes to it but I'm facing some issues where some methods are private or internal and can't be use from my own project.

    Here's the list so far:

    1- GestureTouchesUtility.cs is used in the ARScaleInteractable.cs but the static class is private so I can't access anymore... (Particularly it's calling GestureTouchesUtility.PixelsToInches at line 195). Can we make the GestureTouchesUtility.cs public??

    2-In ARScaleInteractable.cs, it's calling "gesture.Cancel()" at line 204 on the class PinchGesture but the method can't be found. The Gesture has the Cancel method but it's internal... Can we make that protected?

    I'm surprised that I'm facing all those simple issues by simply copying existing interactables to extend them...

    Thank you
     
    jdh5259 and Thimo_ like this.
  2. Thimo_

    Thimo_

    Joined:
    Aug 26, 2019
    Posts:
    59
    This is something im facing too. It would be much better to open up these methods for our custom implementations as you said.
     
    danUnity likes this.
  3. jdh5259

    jdh5259

    Joined:
    Sep 14, 2017
    Posts:
    20
    Same here. A lot of the problems I face creating my own interactables come from not being able to override internal methods.
     
    Thimo_ and danUnity like this.
  4. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    It's definitely a pain... I basically had to copy every interactables, and the even the base interactable and the gesture interactor and even the GestureTransformationUtility to make the required changes...

    There's a lot of stuff that is assumed but that shouldn't be
     
    Thimo_ likes this.
  5. Thimo_

    Thimo_

    Joined:
    Aug 26, 2019
    Posts:
    59
    In my opinion the XR interaction toolkit is the base from which we can make our components. This means that we should be able to use every method from the toolkit to make new components work as desired.
     
    danUnity likes this.
  6. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
  7. TobiLaForge

    TobiLaForge

    Joined:
    Jun 10, 2015
    Posts:
    2
    You can copy the whole packacke from the Library/PackageCache folder to the Packages folder in you projects Root folder (not in your Assets folder, but the Packages Folder next to it). Then you can edit the files or inherit from them, as long you put them in one of the folders of that package. Don't know about updating the package via package manager, this might work if you version control to merge the files.
     
  8. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    @TobiLaForge Yes off course you can always do that but that makes things much harder than it needs to be.

    I ended up copying a bunch of scripts and modifying them.
     
  9. Thimo_

    Thimo_

    Joined:
    Aug 26, 2019
    Posts:
    59
    @chris-massie I can create custom variations of the AR translator, rotator and selector. When I want to create a custom class for the AR scale interactable component I get to this problem.

    Code (CSharp):
    1.  protected override void OnContinueManipulation(PinchGesture gesture)
    2.         {
    3.             m_CurrentScaleRatio += sensitivity * GestureTouchesUtility.PixelsToInches(gesture.gapDelta);
    4.  
    5.             transform.localScale = currentScale;
    6.  
    7.             // If we've tried to scale too far beyond the limit, then cancel the gesture
    8.             // to snap back within the scale range.
    9.             if (m_CurrentScaleRatio < -elasticRatioLimit
    10.                 || m_CurrentScaleRatio > (1f + elasticRatioLimit))
    11.             {
    12.                 gesture.Cancel();
    13.             }
    14.         }
    GestureTouchesUtility.PixelsToInches(gesture.gapDelta): GestureTouchUtility is inaccesible due to its protection level.
    Gesture.Cancel(): Gesture<PinchGesture>.Cancel() is inaccesible due to its protection level.

    How to reproduce: Copy the AR Scale interactable script code to a new file (lets say myCustomScaleInteractable). Then these errors occurs. Would be amazing for my usecase if these protection levels got fixed. I guess others in this thread have some more examples too
     
  10. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    226
    I've captured this as a feature request on our end.
     
    Thimo_ likes this.
  11. Thimo_

    Thimo_

    Joined:
    Aug 26, 2019
    Posts:
    59
    Amazing!
     
  12. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    584
    @chris-massie This seems to be the place for scripting questions for the ARScaleInteractable component. What I'm trying to do is set the scale to maxScale when the object has been placed. When I set that through code it seems to be immediately overwritten to a default scale of (1,1,1). How do I set the starting scale for a placed object that is using the ARScaleInteractable component on it?

    The reason I am doing this is that the AR objects actual sizes are quite large, so the default size of (1,1,1) will create the object at 25% of actual size, which is best used indoors. When the user scales the object to ARScaleInteractable maxSize it is at 100% of actual size.

    When the user is outside, I'd like the same object to be scaled to the maxSize value, i.e. (4,4,4) which makes the object actual sized. In either case, I need to set the default size when the objects are created.
     
  13. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    226
    The
    ARScaleInteractable.OnEnable
    method captures the current local scale of the object and uses it to determine the current scale percentage relative to the min and max scale values. Then every frame during LateUpdate, it updates the
    Transform.localScale
    based on that captured percentage value for the current
    minScale
    and
    maxScale
    values.

    So if you want to adjust the scale of the object after placement (such as if you are listening to the
    ARPlacementInteractable.objectPlaced
    event and scaling the object there), you will need to disable the
    ARScaleInteractable
    behavior and re-enable it so it can recompute the scale correctly in
    OnEnable
    since the field it sets is private.
     
    Voronoi likes this.
  14. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    584
    Thanks for the explanation. I more or less figured this out, since the scene that places the objects at maxScale also does not allow scaling, I disabled ARScaleInteractable for that particular scene. Probably would be better to have a 'desiredScale' in script that scales it after placement as you are describing.
     
  15. GrizzlyFalcon

    GrizzlyFalcon

    Joined:
    Feb 14, 2015
    Posts:
    10
    I am having the exact same issue. I can make my own ARTranslationInteractable and ARSelectionInteractable but not strictly ARScaleInteractable because of the issues laid out previously with dependencies.

    I have slightly gotten around this by inheriting from ARScaleInteractable because I at least have the base class with all it's dependencies however the OnEnable() sets the scale of the object to max scale and there is no start scale available. I am beyond words as to how unusable this makes things whilst otherwise being pretty comprehensive.

    Please can we have an update here on how the request for implementing this is going because I would like to have some expectation management from Unity's side on when we can expect this to work.



    Can I just explain that @chris-massie's solution only works if you are hoping to change the gameObject's CURRENT and ALSO max scale (i.e them being the same thing).


    Either can you provide a way to set a max scale without setting the model's current scale as currently my objects are huge when I set the max scale even when I disabled the scripts as the scale calculation is made ON ENABLE -_-

    or

    Can you guys please fix and implement the desired changes outlined in this forum post i.e to have a current scale independent of max scale


    With an additional update on current progress of this (if any) and how Unity is going to remedy this.


    Appreciate this post is a bit spicy but this is really the stuff that lets unity down.


    Best,
    Sam
     
    Thimo_ likes this.