Page 1 of 1

Disable trigger dialogue while interacting with screen

Posted: Sun Dec 08, 2024 7:12 am
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.

Re: Disable trigger dialogue while interacting with screen

Posted: Sun Dec 08, 2024 8:51 am
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.

Re: Disable trigger dialogue while interacting with screen

Posted: Sun Dec 08, 2024 2:57 pm
by Arctichorse9
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

Posted: Sun Dec 08, 2024 8:24 pm
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 */
    }
}

Re: Disable trigger dialogue while interacting with screen

Posted: Sun Dec 08, 2024 9:05 pm
by Arctichorse9
Thank you so much for looking into this. Where do I put the Custom ProximitySelector code?

Re: Disable trigger dialogue while interacting with screen

Posted: Sun Dec 08, 2024 9:24 pm
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

Re: Disable trigger dialogue while interacting with screen

Posted: Mon Dec 09, 2024 12:41 am
by Arctichorse9
Thank you so much.

Re: Disable trigger dialogue while interacting with screen

Posted: Mon Dec 09, 2024 8:05 am
by Tony Li
Glad to help!