Disable trigger dialogue while interacting with screen

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Arctichorse9
Posts: 46
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Disable trigger dialogue while interacting with screen

Post by Arctichorse9 »

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.
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable trigger dialogue while interacting with screen

Post by Tony Li »

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.
Arctichorse9
Posts: 46
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Re: Disable trigger dialogue while interacting with screen

Post by Arctichorse9 »

Hi. I am using a Proximity Selector and Unity's Input System. Am thinking about a possible work around.
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable trigger dialogue while interacting with screen

Post by Tony Li »

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:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class CustomProximitySelector : ProximitySelector
{
    protected override void Update() {}
    private void LateUpdate() { base.Update(); }
}
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:

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 */
    }
}
Arctichorse9
Posts: 46
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Re: Disable trigger dialogue while interacting with screen

Post by Arctichorse9 »

Thank you so much for looking into this. Where do I put the Custom ProximitySelector code?
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable trigger dialogue while interacting with screen

Post by Tony Li »

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
Arctichorse9
Posts: 46
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Re: Disable trigger dialogue while interacting with screen

Post by Arctichorse9 »

Thank you so much.
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Disable trigger dialogue while interacting with screen

Post by Tony Li »

Glad to help!
Post Reply