Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GUI.TextField doesn't work in UWP ?

Discussion in 'Windows' started by manutoo, Oct 10, 2017.

  1. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    Hello,

    when I build for UWP, the GUI.TextField doesn't work : I press keys on my keyboard, but nothing happen. Input.GetKey() works correctly, though.

    And on the Surface Pro 3 of my customer, touch keyboard doesn't work either for GUI.TextField (maybe it even crashes).

    Is there any special setup to do to make it work ?

    I'm using D3D ; I didn't try with a XAML build.

    Thanks in advance for any help ! :)

    Note: I'm using Unity 5.3.7, so maybe it's an old bug that has been fixed in a more recent version.
     
    Last edited: Oct 10, 2017
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    It should be working, but that is an ancient version of Unity. I can't really say what's going on without seeing the code you're using, though.
     
  3. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    @Tautvydas-Zilys,
    thanks for the reply !

    basically, I do this :
    Code (CSharp):
    1. m_Name = GUI.TextField(InputZone, m_Name);
    Focus, lost of focus & text selection work correctly within the text field.

    I'm using a custom Gui Skin, and a custom GUI.Matrix, if it matters.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    So I made a branch new project in Unity 5.3.5p3 (a little bit older than the one you're using, but that's what I had installed and they should be pretty close), attached this script to an object and built to UWP:

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class NewBehaviourScript : MonoBehaviour
    4. {
    5.     private string m_Name = string.Empty;
    6.     private Rect m_InputZone = new Rect(100, 100, 200, 80);
    7.  
    8.     private void OnGUI()
    9.     {
    10.         m_Name = GUI.TextField(m_InputZone, m_Name);
    11.     }
    12. }
    upload_2017-10-10_13-31-1.png

    Seems to work just fine... Do you have a sample demonstrating it being broken? Do you get any exception thrown?
     
  5. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    I tried your small sample and it worked fine, so I dug deeper into my code and I found the culprit !

    Code (CSharp):
    1.       if (Event.current.button > 0
    2.             && Event.current.type != EventType.Layout
    3.             && Event.current.type != EventType.Repaint)
    4.         {
    5.             if (IsMouseOnGui())
    6.                 Event.current.Use();
    7.            return;
    8.         }
    It was at start of my OnGUI()
    I'm not sure why I had done that, but it was likely for optimization and maybe to avoid clicking on 3D stuff behind the GUI.
    I moved it at end of my OnGUI() and everything seems to be still working, so I'll keep it like that.

    Maybe it could be considered as an Unity bug as this GUI behavior isn't the same on UWP.

    Anyway, thanks again for your help ! :)
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    It's hard to say why that causes the behaviour to be different without debugging...
     
  7. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    @Tautvydas-Zilys,
    I found out why I did that and now I'm sure it's a bug : it's to catch right & middle mouse clicks, to prevent them to activate GUI Button & stuff.
    To the best of my knowledge, this is the way to do that ; it matches this at least : https://docs.unity3d.com/ScriptReference/Event-button.html & https://docs.unity3d.com/ScriptReference/Event.Use.html . Plus it works in Debug, but fails in Master. Usually, I can enter 1 character before it stops to work. It fails both with and without the "return;"

    But it's not the main point of this message.

    I got an exception with touch screen devices when the user click on the GUI.Textfield() input zone. It happened to my customer, to the Microsoft certification Team with the update I uploaded 3 days ago, and also when I run my game in the Visual Studio Simulator :
    2017-10 - TextInput - Exception in Simulator.jpg

    I reported the bug with a test project : # 959376 .

    Please let me know if you think of a workaround, because I guess I can't hope for a bug fix at this point for Unity 5.3... :(
    How maybe I could fix something on the Visual Studio side..?
     
  8. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    I just tested with Unity 5.6.3 and there's no exception anymore.
    The Event.current.Use() still produces the same issue, though.

    EDIT:
    unfortunately, updating to 5.6 might be a long & dangerous process, so I'd still like to find a solution with 5.3 ...
     
    Last edited: Oct 16, 2017
  9. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    Still crashing in 5.3.8 .

    Then I switched to XAML build instead of D3D, and now it works ! I hope the performance drops isn't too bad, but I guess it'll have to do... :cool:
     
  10. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    Despite the text input working in the simulator with a XAML build while it was causing an exception with a D3D build, the update still crashes for the Windows Certification Team, so I guess I'm back to square one... :(
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Did you try enabling mixed mode debugging and breaking on native C++ exceptions to see the callstack where it's coming from?
     
  12. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    No, I didn't try that. I even didn't succeed debugging C# when I hunted another bug (I had to fix it by using my brains, the horror :p ).

    I could try, but to where would it lead me ? It's relatively clear the crash is on Unity side as it's working on 5.6, and I'm short on options now. I think the only thing left to do is to disable GUI.Textfield when there's no physical keyboard (which is a bit problematic as I need the user to enter a name when creating custom characters).
     
  13. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    It would tell you what exactly in Unity is causing that and perhaps you could avoid just using that piece.
     
  14. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    The project in bug report shown above doesn't use anything, only a script handling the GUI elements.

    Anyway, I just converted my project to 5.6, and amazingly, except hundred of warning messages because I have negative scaling values for my colliders, it seems my game is still working..! :D

    I'll fix that bunch of colliders & play a couple of hours to be sure everything is alright, and hopefully I'll be done with it..! :)

    I'll let you know if I finally pass the Windows AppStore checking...
     
  15. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    522
    Microsoft finally accepted the new version and it's in the store now !

    I had to remove support for Windows Mobile to get this result, but as of today, I guess no mobile is powerful enough to run the game.

    According to Microsoft Team, the game was silently crashing during loading on Lumia 1520 & Lumia 950 ; none of them is meeting the minimum requirements I had specified in the App Details, but it didn't stop them to refuse my game for that reason... :confused:
     
  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Congratulations!