#Thread
1 messages · Page 1 of 1 (latest)
In this tutorial, you’ll learn how to customize Interactables with Interactor Events to trigger events, such as cutscenes or animations. You’ll also learn to apply haptic and audio feedback to an Interactor when hovering over or selecting Interactables. Finally, you’ll learn how to use the XR Interaction Toolkit Debugger to track and debug state...
this is for hooking up sound events
but the same theory applies for any purpose
Sound effects?
yes
but it allows you to see the easiest way to just get that working while using simple drag and drop stuff, with minimal scripts
You want each interactable to be on a different layer, if you do not want to lose the ability to grab multiple interactables though
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class InteractableEventDemo : MonoBehaviour
{
public AudioClip hoverEnterSound;
public AudioClip hoverExitSound;
public AudioClip selectEnterSound;
public AudioClip selectExitSound;
public void PlayHoverEnterSound()
{
if (hoverEnterSound != null)
AudioSource.PlayClipAtPoint(hoverEnterSound, transform.position);
}
public void PlayHoverExitSound()
{
if (hoverExitSound != null)
AudioSource.PlayClipAtPoint(hoverEnterSound, transform.position);
}
public void PlaySelectEnterSound()
{
if (selectEnterSound != null)
AudioSource.PlayClipAtPoint(selectEnterSound, transform.position);
Physics.IgnoreLayerCollision(6, 7, true);
}
public void PlaySelectExitSound()
{
if (selectExitSound != null)
AudioSource.PlayClipAtPoint(selectExitSound, transform.position);
Physics.IgnoreLayerCollision(6, 7, false);
}
}
You can see how I modified the code to work for me
you can replace the specific layer numbers with whatever you want
just follow the linked tutorial and drag and drop that script when asked to do that
what kind of project
Ok
im doing simple testing before i start a school project
Alright
Ill follow the tutorial you linked
But
I might still have some questions so if you dont mind can i DM you?
just remember that the layer aspect is not covered in the tutorial, but that is simple googling if thats too weird or anything
uh i dont really want to dm anyone if thats fine by you
Sure
But yeah for the layer aspect just set the object you want to interact with to a layer you want to and do the same with your XR rig as another layer. You won't be able to really hold two objects from the same layer with that setup, but I'm working on a solution for that as well
Your item is then at 7 and the XR rig at 6
Do i drop the code you sent to XRRig?
If you set them to the same they will still collide
OR somewhere else
okõ
The code I sent goes to the interactable event
In the section of the tutorial where it says to put it
Ok
It's basically my substitution for their script in the tutorial
I have my collider on the rig of the player, rather than the hands. The same concept applies regardless
How did you arrange your interactable events?
I have it on both
I put the script you sent me like this on a flashlight
The Flashlight is just a cylinder with lights
and
I put the script you sent me on it
Its not working tho
When i pick it up it still makes me fly
Then you drag that script from your inspector to the interactable event for entering select and exiting select
Can you send a screenshot on where that is please?
Unfortunately not at my computer at the moment, it should be at the element above your script in your screenshot
Oh wait
Almost all the way at the bottom of it
Yep
And remember depending on where you modified the script, you will have your physics behaviour decided by what action is taking place (hoverenter/exit or selectenter/exit)
I havent modified the script
You did
I think im gonna do enter
Because thats when i pick it up right?
Well I mean if you wanted to change it from my version, sorry
But yeah enter is smart because the physics apply until you hold it
And should be re-enabled when you exit it
It goes in None (Object)
It's a placeholder value, you put the reference to the script that's in your inspector to access the functions defined in the script
Alright let me try it now
Good luck
Just remember that this isn't really an ideal solution. Disabling interaction between two entire layers means you can only hold one instance of your object regardless
I think my project is cursed or smth
And you're sure you gave your body/hands another layer?
Layer 6?
If you ever get back on your computer
please consider sending me screenshot of you XROrigin
And object
Because
Currently
This is the first part of my project
and i cant continue with this not working
Wait did you select your function in the drop-down menu after adding the script?
Did you add the script into that slot or the object?
Object
Has to be the script
?
Click and drag your script that is right below it into the slot
Yes
Ok
That allows you to select your script
Lemme try again
Click on no function
And find the select enter and select exit functions in the menu
It's crucial that you get that part
On 'No function ' you can click and maneuver to your new functions from the script
You've basically added the functions but never given Unity the instructions on which function to engage
That isn't good
Whats wrong
Let me get on the computer because that's an issue I had too
It's no problem. I'm a teaching assistant and it also helps me better understand how things work when I can teach it to others
crude picture, but this is what you did, right?
because what it looks like to me is that youve dragged the script from another source, like your assets
Yeah
I did
which creates the result on the bottom event, where you have no access to anything
yeah thats the issue
drag it from your inspector panel only
it needs to come from that because it needs the information from your current object
But then the flashlight says the name of the object
The scripts name changes
when i drag it into
the
how so
Select Entered
yeah if that inspector panel is dragged out enough, you can read that it has the objects name followed by (scriptname goes here)
this is to let you know that it references the objects instance of the script
rather than the script from another source
unity and c# is just a bit weird to get into, but these are the words that i think are the easiest to explain with. sorry if they are not the exact terms
but yeah you have now gotten the script in, now you need to use the dropdown, and go down to the name of the script at the bottom and choose the function name that matches what you want it to do
an instance just means that one existing version of something
you can have a script and have 30 instances of it, but they are all the same script. however those 30 scripts shouldnt depend on each other or behave differently
references in my experience just means that it points to where it comes from. so in this example you are referencing the instance of the script that exists in your object`s inspector panel
yes! perfect, now remember to do it for the other one too, with the event that corresponds, of course
Well
It still doesnt work
Is there anyway you could copy your unity thing into mine
Or i could copy it i mean
Because
This really isnt working for me
And its a hassle for you aswell
it isnt a hassle for me, but i dont know what all of your settings are
first the xr rig
Is it a problem if my things name is XROrigin
no no
so one thing to note is that you dont need the capsule collider nor a rigidbody for this to work, i dont know if they come from other things, but for me that wasnt necessary
i do have it on the hands though
i havent fallen through the ground myself, not sure exactly why though
My hands are made like this
with a bazillion different capsule colliders to follow
the fingers
nice hands, havent gotten down to make such myself, but they look nice!
Theyre pretty shit
stuff still falls through my fingers
but
i dont care about that right now
Everything is on 6
I set the XR origin on 6
so all the children went with him
💀
Came off a bit weird
yeah thats how it should be
im going to be honest, i dont know why either right now. wish it was easier to debug other peoples stuff 😅
your setup looks like it should work
this is my object
Ok
my GrabInteractable is a bit modified
and i think it might be an issue
It has two Attach Transform
s
this is the general overview other than that
could potentially be an issue, i dont know much about those
try disabling them and see if the issue persists
Let me use the default one
go ahead
and did you then add the script again?
OH yeah
No
I didnt do anything
wait
Beatiful
Amazing
Zesty
Deviously great
THANK YOU SO MUCH
IT WORKED!
VERY NICE
glad to hear it
now just remember that if you were to have two of those flashlights
you would have to pick them up at the exact same time or else you lose the ability to pick up a second
that can be resolved with some modification of the technique and code, but thats just details details
if you find a way before i do haha
Still one issue
yea?
I cant grab it with my left hand
that would be because you havent set up the interactor for the left hand
oh and you also cant take it from one hand to another while holding it
so... some issues. obviously 🙃
im not a teacher or going to be one (i hope), but i do enjoy giving simple help
Yeah that was the problem
I was just used to it
Alright
NVM then
but
Still a great help
yeah that is something that is probably possible to solve by making each hand unique and disabling collision only between that one hand and the object
i think you could figure that one out yourself, but do keep a backup of the "success" for now at least
Alright
glad i could be of some help, lmk if you find success with modifications as well. seems very doable but i am not really in the mindspace to get that working straight away