- Home /
Event.current.Use makes GUI disapear ONLY in standalone
Ok, so I have been spending my entire day trying to figure a work around this unity bug, and I am starting to get to the end of my rope. I can guarantee you it is a bug because in the unity editor it works fine, but in the standalone it doesn't.
Main problem is that the tab key does horrible things to the GUI (such as trying to change GUI focus to a text field) even if you don't want it to. So I have looked at umpteen threads that suggest how to solve this problem.
Some suggest use:
if (Event.current.keyCode == KeyCode.Tab || Event.current.character== '\t')
Event.current.Use()
... well the problem with that is it makes my entire GUI disappear until another input is detected (when built only). Putting it at the end of the OnGUI() stops that single script's OnGUI() from disappearing but all other script's OnGUI() still disappear. I was able to have some luck in a separate project where if I change the execution order of the script that has the above code to first, then none of the GUI disappeared. But if I do the same in my main project, I still get disappearing GUI elements. Unlucky?
There is obviously a critical Unity problem here because in the editor its fine but in the standalone its not, so that's a big enough issue, so I have been trying for quite some time to figure out a work around but only to some avail.
I totally need to step away for a bit because, damn... but I would even be willing to pay someone to figure this out...Why cant unity just make it so that tab doesn't automatically try to swap between windows, and if you want to enable it you can. Don't force features on us, especially when they break other systems?
Answer by Teddy_p · Sep 06, 2014 at 08:37 AM
Ok so BoredMormon definitely led me in the right direction.
what ended up working was
if (Event.current.type == EventType.keyDown && (Event.current.keyCode == KeyCode.Tab || Event.current.character == '\t'))
{
Event.current.Use();
}
Thanks! ... still would sorta hope unity guys fix the difference between the standalone and editor when using Event.current.Use() though :)
Answer by Kiwasi · Sep 06, 2014 at 01:01 AM
I'm no expert on the GUI system, but I have a hunch that your layout event is being used. So everything that comes after does not get processed.
I suggest checking the event type. Add a condition to your if that checks that the event type is not a layout event. Can't tell you exactly how to code this, but you should be able to get through the docs from here.
I changed it to
if (Event.current.type != EventType.Layout && (Event.current.keyCode == $$anonymous$$eyCode.Tab || Event.current.character== '\t'))
Event.current.Use()
but still have issues.
I had the same issue and checking the event type solved it.
Am I reading the docs wrong or should it be EventType.Layout ins$$anonymous$$d?
Also might want to consider brackets to logically arrange your && and || 's
yes I edited the previous to reflect exactly what I had in the code... obviously it wouldn't have been able to compile if I used a lowercase.... The point still stands that the editor and game have different results.