Hi. I'm building for Android and have dialogues set up on NPCs using On Use to trigger the dialogue so that when you're close to the NPC and tap on it, the dialogue triggers. All that is working fine.
But--I have buttons on the screen to tap on to open the inventory and the quest Log and when I am close to an NPC and tap on those buttons, the tap also triggers the dialogue which is not desirable.
Is there a way to disable the triggering of the dialogue while tapping on those buttons?
Any help is appreciated.
Disable trigger dialogue while interacting with screen
-
- Posts: 46
- Joined: Wed Sep 25, 2024 11:26 pm
- Location: New York City
- Contact:
Re: Disable trigger dialogue while interacting with screen
Hi,
You're using Proximity Selector, correct?
Please remind me which input system you're using. With Unity's built-in input manager or Rewired or InControl, if you tap on an area of the screen blocked by another button on a higher Canvas sort order (such as your inventory button), it won't send OnUse to the NPC. The Proximity Selector checks Unity's EventSystem.IsPointerOverGameObject() method, which checks if the tap location is on a UI GameObject (i.e., button). However, EventSystem.IsPointerOverGameObject() method is bugged in the Input System package, so you'll need to implement a workaround if you're using the Input System package.
You're using Proximity Selector, correct?
Please remind me which input system you're using. With Unity's built-in input manager or Rewired or InControl, if you tap on an area of the screen blocked by another button on a higher Canvas sort order (such as your inventory button), it won't send OnUse to the NPC. The Proximity Selector checks Unity's EventSystem.IsPointerOverGameObject() method, which checks if the tap location is on a UI GameObject (i.e., button). However, EventSystem.IsPointerOverGameObject() method is bugged in the Input System package, so you'll need to implement a workaround if you're using the Input System package.
-
- Posts: 46
- Joined: Wed Sep 25, 2024 11:26 pm
- Location: New York City
- Contact:
Re: Disable trigger dialogue while interacting with screen
Hi. I am using a Proximity Selector and Unity's Input System. Am thinking about a possible work around.
Re: Disable trigger dialogue while interacting with screen
Hi,
I looked at ProximitySelector, and it's Selector, not ProximitySelector, that has to handle the Input System bug. I think the issue here is that tapping the Usable NPC happens on the same frame as tapping the inventory button, so they both happen. Assuming the inventory button temporarily disables the ProximitySelector in addition to opening the inventory UI, you can make a subclass of ProximitySelector like this:
This moves the check to LateUpdate(), after the inventory UI would have disabled ProximitySelector.
If opening the inventory UI doesn't disable ProximitySelector, then you can write some code to check:
I looked at ProximitySelector, and it's Selector, not ProximitySelector, that has to handle the Input System bug. I think the issue here is that tapping the Usable NPC happens on the same frame as tapping the inventory button, so they both happen. Assuming the inventory button temporarily disables the ProximitySelector in addition to opening the inventory UI, you can make a subclass of ProximitySelector like this:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class CustomProximitySelector : ProximitySelector
{
protected override void Update() {}
private void LateUpdate() { base.Update(); }
}
If opening the inventory UI doesn't disable ProximitySelector, then you can write some code to check:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class CustomProximitySelector : ProximitySelector
{
protected override void Update() {}
private void LateUpdate()
{
if (IsAnotherUIOpen()) return;
base.Update();
}
private bool IsAnotherUIOpen()
{
return /* your code here to check if the Proximity Selector should *not* be used right now */
}
}
-
- Posts: 46
- Joined: Wed Sep 25, 2024 11:26 pm
- Location: New York City
- Contact:
Re: Disable trigger dialogue while interacting with screen
Thank you so much for looking into this. Where do I put the Custom ProximitySelector code?
Re: Disable trigger dialogue while interacting with screen
Hi,
Put it in your own script folder. Then use CustomProximitySelector in place of ProximitySelector. You can swap them out in-place on the inspector: instructions
Put it in your own script folder. Then use CustomProximitySelector in place of ProximitySelector. You can swap them out in-place on the inspector: instructions
-
- Posts: 46
- Joined: Wed Sep 25, 2024 11:26 pm
- Location: New York City
- Contact:
Re: Disable trigger dialogue while interacting with screen
Thank you so much.