Search Unity

Resolved Mixing button control with interactable

Discussion in 'AR' started by MrChrisAnt, Jul 2, 2021.

  1. MrChrisAnt

    MrChrisAnt

    Joined:
    May 18, 2021
    Posts:
    5
    I’ve been trying for a few weeks to extend the functionality of the ARFoundation samples interaction scene (where you scan the floor, click somewhere and you can place an instance of a prefab then move, scale and rotate with touch gestures. I want to also be able to use button controls to further move and orientate either the object, or even just it’s first child. I have been unsuccessful so far. I have a setup that works with a normal instance but I don’t know how to pass the AR instance to my button/game manager which holds that code.

    Same problem with the multi image tracking scene. I want to track and then use buttons to fine tune the placement relative to it hence why I’d consider moving the child node. Either way, I don’t seem to be able to access the placed instance through my button script.

    Many thanks.
     
  2. ACWesterberg

    ACWesterberg

    Joined:
    Oct 21, 2018
    Posts:
    11
    What i've done to solve the instancing, is I've given the prefab that I wish to place a tag. And that tag could be something like ARObject. In the code for button presses and such I use the FindGameObjectWithTag("ARObject"), and then GetComponent to use the code within scripts on that object.
     
    MrChrisAnt likes this.
  3. MrChrisAnt

    MrChrisAnt

    Joined:
    May 18, 2021
    Posts:
    5
    Thank you so much. I’ll give that a go. I am currently putting all my button code into the same ARPlacmentInteractable script that I create the instance from. It’s a dirty hack and it’s not working yet but that’s probably me just not really being a developer. Thanks again - good idea!
     
  4. MrChrisAnt

    MrChrisAnt

    Joined:
    May 18, 2021
    Posts:
    5
    ARScaleInteractable seemed to be overriding my secondary scaling of the instance as controlled by a button. I noticed that it momentarily jumped to the scale and immediately back. The hack I took to that was to just scale up the child of the instance instead of the instance itself. So the interactable scales the instance and the buttons scale a group under the instance. Horrible hack but it’s working for now.