Completely prevent Dialogue System from using EventSystem?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Jamez0r
Posts: 59
Joined: Fri Nov 20, 2020 8:18 pm

Completely prevent Dialogue System from using EventSystem?

Post by Jamez0r »

Update in comment below - I believe I found a solution.

Hey Tony - was really hoping to get this one figured out on my own but I've been struggling with this for a couple hours now.

Long story short, the input-handling for my game is pretty complex (the game has singleplayer, local 2 player coop, online 2 player coop) to the point where I've created my own system for handling input (directly from polling rewired) specifically to control the Dialogue System. I am still using unity's EventSystem for the rest of the game's UI like menus, but not for the Dialogue System.

Everything with my setup is working great except for one thing. I need the Dialogue System to never set the unity EventSystem's "Selected Gameobject" aka EventSystem.setSelectedGameObject(...).

In VisualStudio, I searched for all references to the EventSystem.setSelectedGameObject(...) in my entire project, and for all of them within the PixelCrushers namespace I removed the function call (commented it out), and for the rest of the references in my project I added a Debug.log so that I could keep track of it being called.

Unfortunately, when a conversation starts and every time it progresses to a new line of dialogue, the EventSystem's currentSelectedGameObject is set to the NPC Subtitle Panel's "Continue Button".

I honestly don't know how this is possible, since I've either commented out all instances of the EventSystem.setSelectedGameObject() function calls, or added my Debug.Log() line right before it (which doesn't appear in console when the Continue Button is mysteriously selected).

Might there be some other "untrackable" way that the Continue Button is being set as the EventSystem's selected gameobject? Like a UnityEvent thats doing it, or something?

I've been scratching my head on trying to figure out how I can even track down where in the code/project that it is being set. As far as I know there isn't a way to "stack trace" the EventSystem's currentSelectedGameObject being set, which leaves me to simply guessing at what could be going on.

Any ideas on what/where I could check? :oops:

Edit to add more info: I still need to be able to detect mouse-clicks on the Dialogue System's UI components, so I still have to have the Button component on things like the Continue Button and the Response Buttons. So I'm technically still using unity's EventSystem for that. That is actually the source of the issue, because if a Button is the currentlySelectedGameObject, and you press the Submit button on a gamepad, it fires the OnClick() on the Button (which you can't distinguish from an actual mouse click, which I need to be able to do). That's the thing that is screwing things up for me, so I am trying to make sure that none of the Dialogue System's UI components ever become the currentlySelectedGameObject to prevent that.

----------------

I was also considering another option, which would be to simply detect if any of the Dialogue System's UI components are being Selected (I tried using an "Event Trigger" component with a trigger for Selected), and to then just call EventSystem.setSelectedGameObject(null).
But you get an error ("Attempting to select myGameObject while already selecting an object") if you try to set the EventSystem's selected game object from a callback of it having been set.
I considered that I could just 'wait till end of frame' and then set the selectedGameObject to null, but I'm worried if that will result in a 1-frame moment where it receives the EventSystem input (Submit, etc). So I'm not sure if this is even a good route to explore .


Thanks for any help/suggestions!!
Last edited by Jamez0r on Fri Oct 07, 2022 8:09 pm, edited 2 times in total.
Jamez0r
Posts: 59
Joined: Fri Nov 20, 2020 8:18 pm

Re: Completely prevent Dialogue System from using EventSystem?

Post by Jamez0r »

Quick reply - I may have figured out a solution, testing it now

Update: Looks like a UI Button's OnClick() is called when pressing Submit on a gamepad (if the button is the currentlySelectedGameObject), but if you instead use an EventTrigger with PointerClick, then it ONLY gets called when clicking the mouse.

Wish I had known that earlier :lol: :lol: I was going to drastic measures to try to separate the two.

I still wouldn't mind figuring out why the Continue Button is being set as the EventSystem's currentlySelectedGameObject, just so I can completely rule out the Dialogue System from ever messing with the 'currentlySelectedGameObject'. But if I can't figure that out, I can probably still manage to do what needs to be done :)
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Completely prevent Dialogue System from using EventSystem?

Post by Tony Li »

Hi,

To prevent the Dialogue System's UIs from setting the selected GameObject:
  • On the Dialogue Manager GameObject's Input Device Manager component, set Input Device to Mouse, clear all of Joystick *** To Check and Key *** To Check lists.
  • Inspect the subtitle panels, response menu panel(s), and quest log window. Set Focus Check Frequency and Refresh Selectables Frequency to 0.
Post Reply