Skip to main content
filmgrvin
New Participant
Mar 13, 2024 7:52 PM UTC
Solved

Artificially triggering a snap interaction via code

I'm trying to instantiate both a SnapInteractable and SnapInteractor from code. After both objects are instantiated, I want to then attach the interactor to the interactable.

Here's a demo video to demonstrate what I'm going for: https://www.dropbox.com/scl/fi/zcpshr4bjw2okacy0ae29/2024-03-13-at-12.49.17.mp4?rlkey=so0s0r316vykvir8u0eq743ja&dl=0

The only way I can get the interaction to occur is by using my hand to grab the interactor, and place it near the interactable.

I've tried setting the position via code (hoping proximity would trigger a snap interaction), but no luck.

I've also tried using the following code but no luck there either.

interactable.AddSelectingInteractor(interactor);
interactor.Select();
 
 
Any ideas?
    This topic has been closed for replies.
    BigFlex
    BigFlexAnswer
    Meta Employee
    Mar 25, 2024 4:08 PM UTC

    Hi filmgrvin, the SnapInteractor has some methods you can use to force select the interactor, like this:

    SnapInteractor.SetComputeCandidateOverride(() => SnapInteractable); SnapInteractor.SetComputeShouldSelectOverride(() => true);
     
    This will force-set the candidate of the interactor to the correct interactable, and then force it to select (snap).

     

    7 replies

    filmgrvin
    filmgrvinAuthor
    New Participant
    Mar 14, 2024 12:11 AM UTC

    Just wanted to add, if the _defaultInteractable field on SnapInteractor was public, this would be a non-issue...

    BigFlex
    BigFlexAnswer
    Meta Employee
    Mar 25, 2024 4:08 PM UTC

    Hi filmgrvin, the SnapInteractor has some methods you can use to force select the interactor, like this:

    SnapInteractor.SetComputeCandidateOverride(() => SnapInteractable); SnapInteractor.SetComputeShouldSelectOverride(() => true);
     
    This will force-set the candidate of the interactor to the correct interactable, and then force it to select (snap).

     

    filmgrvin
    filmgrvinAuthor
    New Participant
    Mar 28, 2024 1:20 AM UTC

    Oh my goodness thank you so much! That worked, you're a life saver

    BigFlex
    Meta Employee
    Mar 28, 2024 3:25 PM UTC

    I'm glad I could help 🙂 If you have any questions about Interaction SDK in the future, please tag me; I write the docs for the team and also engage with users here on the forum! Did you try using any of the official documentation to answer your question? If you did, I'm always looking for gaps in it and ways to make it more usable, so I'd love your feedback.

    BigFlex
    Meta Employee
    Jul 31, 2024 4:31 PM UTC

    Hi, I've switched teams and no longer work on Interaction SDK, but you can direct any questions to @ffejnosliw. Thanks 🙂