#Thread

1 messages · Page 1 of 1 (latest)

iron shuttle
#

Here

tired storm
#
Unity Learn

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

iron shuttle
#

Sound effects?

tired storm
#

yes

iron shuttle
#

Cool

#

i want to make sound effects aswell

tired storm
#

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

iron shuttle
#

So

#

Im not really following

#

Just curious

#

what are you even working on

#

like

tired storm
#

just follow the linked tutorial and drag and drop that script when asked to do that

iron shuttle
#

what kind of project

tired storm
#

im doing simple testing before i start a school project

iron shuttle
#

Alright

#

Ill follow the tutorial you linked

#

But

#

I might still have some questions so if you dont mind can i DM you?

tired storm
#

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

iron shuttle
#

Sure

tired storm
#

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

iron shuttle
#

So if i set my Item to layer 7

#

i should set my XROrigin to that too

#

Also

tired storm
#

Your item is then at 7 and the XR rig at 6

iron shuttle
#

Do i drop the code you sent to XRRig?

tired storm
#

If you set them to the same they will still collide

iron shuttle
#

OR somewhere else

tired storm
#

The code I sent goes to the interactable event

#

In the section of the tutorial where it says to put it

iron shuttle
#

Ok

tired storm
#

It's basically my substitution for their script in the tutorial

iron shuttle
#

I cant Pick up the item anymore

#

Do you have colliders on your hands?

tired storm
#

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?

iron shuttle
#

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

tired storm
#

Then you drag that script from your inspector to the interactable event for entering select and exiting select

iron shuttle
#

Can you send a screenshot on where that is please?

tired storm
#

Unfortunately not at my computer at the moment, it should be at the element above your script in your screenshot

iron shuttle
#

Oh wait

tired storm
#

Almost all the way at the bottom of it

iron shuttle
#

Here?

tired storm
#

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)

iron shuttle
#

I havent modified the script

#

You did

#

I think im gonna do enter

#

Because thats when i pick it up right?

tired storm
#

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

iron shuttle
#

Alright but

#

I cant really put the interactable Event Demo anywhere

tired storm
#

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

iron shuttle
#

Alright let me try it now

tired storm
#

Good luck

iron shuttle
#

Yeah no

#

It still makes me float

tired storm
#

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

iron shuttle
#

I think my project is cursed or smth

tired storm
#

And you're sure you gave your body/hands another layer?

iron shuttle
#

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

tired storm
#

Wait did you select your function in the drop-down menu after adding the script?

iron shuttle
#

This?

tired storm
#

Did you add the script into that slot or the object?

iron shuttle
#

Object

tired storm
#

Has to be the script

iron shuttle
#

?

tired storm
#

Click and drag your script that is right below it into the slot

iron shuttle
#

Like this

tired storm
#

Yes

iron shuttle
#

Ok

tired storm
#

That allows you to select your script

iron shuttle
#

Lemme try again

tired storm
#

Click on no function

#

And find the select enter and select exit functions in the menu

#

It's crucial that you get that part

iron shuttle
#

That?

tired storm
#

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

iron shuttle
#

I dont know what to choose here

tired storm
#

That isn't good

iron shuttle
#

Whats wrong

tired storm
#

Let me get on the computer because that's an issue I had too

iron shuttle
#

Sure

#

thing

#

Also i really want to thank you for helping me so much

tired storm
#

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

tired storm
#

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

iron shuttle
#

But then the flashlight says the name of the object

#

The scripts name changes

#

when i drag it into

#

the

tired storm
#

how so

iron shuttle
#

Select Entered

tired storm
#

screenshot that please

#

it says ObjectName (scriptname) basically, no?

iron shuttle
tired storm
#

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

iron shuttle
#

I dont know what the exact words mean anyway

#

soi

tired storm
#

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

iron shuttle
#

Like that?

tired storm
#

yes! perfect, now remember to do it for the other one too, with the event that corresponds, of course

iron shuttle
#

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

tired storm
#

it isnt a hassle for me, but i dont know what all of your settings are

iron shuttle
#

Ok

#

What settings would you like to see?

tired storm
#

first the xr rig

iron shuttle
#

Is it a problem if my things name is XROrigin

tired storm
#

no no

iron shuttle
#

Alrighjt

tired storm
#

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

iron shuttle
#

But if i get rid of it

#

DOesnt it mean i fall through the ground

tired storm
#

i do have it on the hands though

iron shuttle
#

Me too

#

I like physics but

#

I have it a little differently i think

tired storm
#

i havent fallen through the ground myself, not sure exactly why though

iron shuttle
#

My hands are made like this

#

with a bazillion different capsule colliders to follow

#

the fingers

tired storm
#

nice hands, havent gotten down to make such myself, but they look nice!

iron shuttle
#

Theyre pretty shit

#

stuff still falls through my fingers

#

but

#

i dont care about that right now

tired storm
#

eh could be worse in VR

#

anyway

#

what layer are those on?

iron shuttle
#

Everything is on 6

#

I set the XR origin on 6

#

so all the children went with him

#

💀

#

Came off a bit weird

tired storm
#

yeah thats how it should be

iron shuttle
#

but

#

Ok good

#

but

#

I still dont understand why i fly away

tired storm
#

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

iron shuttle
#

Ok

#

my GrabInteractable is a bit modified

#

and i think it might be an issue

#

It has two Attach Transform

#

s

tired storm
#

this is the general overview other than that

tired storm
#

try disabling them and see if the issue persists

iron shuttle
#

Let me use the default one

tired storm
#

go ahead

iron shuttle
#

I used the Default XR Grab Interactable

#

Still no use

tired storm
#

and did you then add the script again?

iron shuttle
#

OH yeah

#

No

#

I didnt do anything

#

wait

#

Beatiful

#

Amazing

#

Zesty

#

Deviously great

#

THANK YOU SO MUCH

#

IT WORKED!

#

VERY NICE

tired storm
#

glad to hear it

iron shuttle
#

IF YOUR GONNA BE A TEACHER OR WHATEVER

#

Then shits gonna be fire'

tired storm
#

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

iron shuttle
#

Oh

#

Uhh

tired storm
#

that can be resolved with some modification of the technique and code, but thats just details details

iron shuttle
#

Should i modify your code then?

#

Alright

#

BUt

tired storm
#

if you find a way before i do haha

iron shuttle
#

Still one issue

tired storm
#

yea?

iron shuttle
#

I cant grab it with my left hand

tired storm
#

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

iron shuttle
#

I was just used to it

iron shuttle
#

NVM then

#

but

#

Still a great help

tired storm
#

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

iron shuttle
#

Alright

tired storm
#

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

iron shuttle
#

Do i Write here?

#

Or