Completely prevent Dialogue System from using EventSystem?
Posted: Fri Oct 07, 2022 7:30 pm
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?
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!!
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?
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!!