Is it possible to perform collision detection using Layer on VRchat?

Hello. I want the object to switch the active state on and off when it collides with a particular layer, which worked on Unity but not on VRchat. Is there a way to detect a specific object and raise a collision event?

Two issues I see at a glance:

  • A null check is needed on the game object and collider you retrieve from the collision object. This is because Udon triggers collision events for objects that you’re not allowed to access (eg avatar colliders or the vr camera). If you fall to do a null check your code will crash when this happens.
  • I’ve never tried converting layer numbers to strings, but I wouldn’t be surprised if layer names aren’t being applied. Try comparing based on layer number instead.
1 Like

BD’s points are both correct. I have filtered for layer number and that works fine.

Additionally, it is possible to filter for one specific object by getting the name of the GameObject and running a string comparison.

I also strongly suggest looking into Physics.IgnoreCollision, and programming this graph to start ignoring collisions that don’t pass your filter, so that it doesn’t have to run again and again.

1 Like

Thank you for your reply.
I’m trying to uncheck the player that returns null in the layer settings.
About collision detection. I decided to refer to the object itself instead of checking it in layers.

The collider get gameObject node may crash if the collider is null.