OntriggerEnter event gives a null reference if a player enters the collider
complete
Cibbi
When using the On trigger enter event on an object with a collider, the "other" variable usually gives an instance collider of the object that entered that collider. This works for arbitrary scene objects, but fails when the object entering it is the player object, which will cause the udonVM to generate a null reference exception. down below a picture for a minimum graph setup that generates this error.
Log In
Momo the Monster
complete
Momo the Monster
Momo the Monster
in progress
The planned path forward are four new events that will be available: OnPlayerTriggerEnter/Exit and OnPlayerCollisionEnter/Exit that return VRCPlayerApi objects. Also, Trigger/Collider events should no longer give null refs, as they are routed into these new events when they are caused by a Player.
PhaxeNor
Momo the Monster: Thank you Momo! <3
FairlySadPanda
Momo the Monster: PogChamp.
Helpful Helper
Momo the Monster
tracked
We'll make an example of the best way to interact with a player collider.
indominablerexx
Would be so much easier than using a different layer and box colliders with triggers
Helpful Helper
Pretty sure this is not a bug. AFAIK the Player Object is especially protected from accessing it, so itll always return null. Might also be a result of Player Character Controller having special "rules" for collision detection (aka it doesnt behave like just another Collider). There actually is a OnCharacterControllerHit or something like that but it gives you a Type that to my testing is unusable.
Might also have to do with:
Cibbi
Helpful Helper: yes with some more testing afterwards i kinda guessed it was done on purpose (rip my clones dancing), but in that case a better exception message would help understand why instead of a null reference. Something among the lines of the error message happening with the getGameobject function of the VRCPlayerApi would be better.
And btw no, is not special rules for collision, any type of collision with anything inside the player object turns out to be null (tested with a pill collider in a object inside the armature of my avatar, same result of the player object one).
poplopo
How can this be intentional? Accessing the player's collider is in the guidance for detecting player collision: https://ask.vrchat.com/t/player-collision-in-udon/428
Helpful Helper
poplopo: The player object is protected for security/stability reasons. Thats why you cant access it. And in my guide youre never accessing the player collider. You have a layer that only collides with the playerlocal layer.