Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

InputField only works with some Stylesheets

Discussion in 'UI Toolkit' started by Wobbers, Jul 8, 2020.

  1. Wobbers

    Wobbers

    Joined:
    Dec 31, 2017
    Posts:
    43
    I have an issue getting InputFields to work in PlayMode with a custom stylesheet. It is not possible to type in any characters while it is active and also can't select its content. There is no error/etc. just nothing happens at all except the input cursor showing up.

    Looks like the issue is depending on which stylesheet is used. When using Default.uss everything works perfectly, but I also tried some other Unity-Stylesheets and while it works with some it doesn't with others.

    Is there any specific attribute that is required/disallowed in the stylesheet for the InputField to work? Or is it a bug?
     
  2. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    103
    The Default.uss style sheet has the base style for all UI supported in runtime and for now it's the one you should leave set on the Panel Settings unless you're willing to provide all the base styles you'll need.
    For your particular UXMLs you can set style directly on it, or even assign more style sheets by code if necessary.
    If you use the UI Builder, style sheets are added to the UXML automatically for you.

    Hope it helps!
     
  3. Wobbers

    Wobbers

    Joined:
    Dec 31, 2017
    Posts:
    43
    I found the missing property, thanks, you pointed me into the right direction. I had a look at the UI Builder which selectors were missing in my uss.
    Adding the missing selectors did not help, but I found --unity-selection-color was defined in .unity-base-field__input in the Builder, which was not set on that selector inside my uss.

    After adding --unity-selection-color, typing in the InputFields is now possible :)

    Selection also works but the cursor is weird at some positions and the field stretches sometimes
    upload_2020-7-9_17-3-59.png

    Also in my multiline input field, the cursor always stays in the top row while typing only following on the column
    upload_2020-7-9_16-53-42.png

    Since this works as well with the default.uss I guess this is a styling issue as well that I will figure out eventually and not a bug, but I wanted to mention it just in case.
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    945
    UI Builder now has a dedicated Editor Extensions Authoring mode you have to enable via the Canvas properties (click on the Canvas header in the Viewport). This mode adds (back) the Editor-specific controls to the Builder's Library, and does so with a very explicit "Editor-Only" tag.

    The reason for this explicit mode is that many Editor-specific controls will not work at runtime. They will still _appear_ to work when playing the game inside the Editor via the Game view, but they will not work (or even cause a build break) when building your player. This is because many such controls are in the UnityEditor assembly.

    This is also the reason Default.uss does not address some of the Editor-specific controls and why they look a bit off in the Game view.

    We will slowly migrate more and more controls to be ready for runtime and we're also working on improving the default runtime theme (Default.uss), as well as adding a proper theming authoring and managment system (ie. creating your own application-wide Default.uss). Until then, be aware of these limitations and make sure to build your Player often to ensure you're not going to find some surprises. To be really safe at runtime, you should NOT have the Editor Extension Authoring mode enabled in the UI Builder.
     
  5. Wobbers

    Wobbers

    Joined:
    Dec 31, 2017
    Posts:
    43
    Sorry, I don't see the connection here. Is InputField supposed to be Editor-only for now? Because it is available for me in UI builder with Editor Extension Authoring off (It is listed as "Text Field", sorry I used the wrong term before).

    Text Fields behave as expected with Default.uss, but my problem was that they did not with my custom uss because I had a .unity-base-field__input selector defined, but it did not set --unity-selection-color inside.
     
  6. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    945
    Mostly adding context. Sorry for the TMI. Yes, if it's there with Editor Extensions Authoring off, it's fair game.

    Until proper theming support is added, you should always use the Default.uss in your PanelSettings assets and use your own custom USS files as part of the UXML assets attached to UIDocuments. You should not try to make your own Default.uss or you're going to constantly run into styling problems. There's a lot of boilerplate styling in Default.uss, like paddings and margins, that are required for the default controls be usable.

    The focus should be on overwriting the styles you want to change from inside your own USS (which will always take precedence over Default.uss).
     
    Wobbers likes this.
  7. Wobbers

    Wobbers

    Joined:
    Dec 31, 2017
    Posts:
    43
    Ah I see. Thanks for clarification, that explains the things that are going on.
     
unityunity