Page 1 of 1
Selector in 2D not working
Posted: Wed Apr 27, 2022 7:50 pm
by nikki
I'm having major trouble with getting started. I've watched the tutorial series on you tube, and read through the starting docs. I've even managed to get it working in the demo scene, but as soon as I move into my own project, the Selector isn't registering for onUse/onTrigger etc.
I've triple checked the list provided in the FAQs around Selectors in a 2D world (2D collider, layer, 9999 detection distance, runRaycasts, orthographic camera, disabled my entire UI), and tried on multiple different objects but no luck. I know the UI etc. is working because I can get 'onStart' to work just fine, it's just the Selector that isn't playing ball. Is there a way I can see what the raycast is doing or somehow see more information on what has gone wrong?
Re: Selector in 2D not working
Posted: Wed Apr 27, 2022 8:22 pm
by Tony Li
Hi,
You've probably already gone through
How To: Fix Selector Issues, but here are some things to check:
- 2D Only: Camera is set to Orthographic.
- 2D Only: Scripting define symbol USE_PHYSICS2D is set.
- GameObject with Usable component and Dialogue System Trigger has a collider that's enabled.
- GameObject is on a layer included in the Selector's Layer Mask.
- Set Selector's Max Selection Distance is far enough for a raycast from the camera to reach it.
- Run Raycasts is set to In 2D or 3D depending on whether you're using 2D or 3D colliders..
- A transparent UI element isn't blocking collider.
Make sure you've ticked the USE_PHYSICS2D checkbox in the Dialogue System's Welcome Window or selected menu item Tools > Pixel Crushers > Common > Misc > Enable Physics2D Support. (They both do the same thing: setting the scripting define symbol USE_PHYSICS2D.)
Re: Selector in 2D not working
Posted: Thu Apr 28, 2022 3:23 am
by nikki
Yeah, I'm afraid I've tried those already. I'm in a 2D environment, and all of those things look fine, as far as I can tell. I'm trying to import it into unity's example platformer, if that helps?
Re: Selector in 2D not working
Posted: Thu Apr 28, 2022 8:30 am
by Tony Li
There shouldn't be any issue with Unity's example platformer.
Can you send a
reproduction project to tony (at) pixelcrushers.com?
Re: Selector in 2D not working
Posted: Fri Apr 29, 2022 10:45 am
by Tony Li
Thanks for sending the reproduction project.
The Player's Selector is configured to check for Usables that are on the Default layer:
- selectorLayerMask.png (11.68 KiB) Viewed 554 times
But the Enemy is on an undefined layer:
- selectorEnemyLayer1.png (10.23 KiB) Viewed 554 times
Normally, simply setting the Enemy to the Default layer will allow the Selector to detect it:
- selectorEnemyLayer2.png (9.26 KiB) Viewed 554 times
However, Cinemachine throws a wrench into that idea because it has a GameObject named "CinemachineConfiner" that's also on the Default layer and blocks the Selector's raycast. If you change CinemachineConfiner to a different layer, such as Ignore Raycast, it won't block the Selector.
- selectorCinemachineConfiner.png (10.38 KiB) Viewed 554 times
Alternatively, you could tick the Selector's Raycast All checkbox. This tells the Selector to run a raycast through everything it hits, ignoring closer blocking objects that don't have Usable components, until it finds a Usable component.
Another alternative would be to change the Enemy's layer to a new layer such as "Enemy", and set the Selector's Layer Mask to that same layer.