Search Unity

USS and UXML support in Visual Studio

Discussion in 'UIElements' started by TheValar, Apr 18, 2019.

  1. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    752
    Just checking out UI Elements this week and Visual Studio doesn't seem to recognize uss files as anything other than plain text. Is there anything specific I need to do to get good styling and autocomplete features for uss in Visual Studio?

    Note:
    using visual studio 2017 professional
    uxml seems somewhat ok but formatting is a bit weird so perhaps it could be better with some configuration
     
  2. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    38
    Hi,

    USS is a small subset of CSS so any CSS plugin should help.
    I personally use Visual Studio Code for USS files and it works out of the box as long as you add the file association in your setting.
     
  3. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    752
    I assume that means there will be no indication in the IDE if you use valid css that is unsupported by USS right? And same with autocomplete suggestiosn
     
  4. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    38
    TheValar likes this.
  5. STG_

    STG_

    Joined:
    Jun 6, 2018
    Posts:
    1
    Easy solution.

    Within Visual Studio 2019 navigate to:
    Tools => Options => TextEditor => File Extensions

    1. Enter the text "uss" (without quotes) into the box "Extension"
    2. Select "CSS Editor" from the drop-down list labelled "Editor"
    3. Click "Add", then click "OK"

    Close Visual Studio and relaunch from within Unity. You now have CSS highlighting.

    The only warning I'd give you: this is full CSS highlighting, and obviously Unity's USS only supports some of the properties, but you can work that out here:
    https://docs.unity3d.com/Manual/UIE-USS-SupportedProperties.html
     
  6. Trinary

    Trinary

    Joined:
    Jul 26, 2013
    Posts:
    342
    Where can I find this uss validation system? So far as I can tell my USS is unvalidated on 2019.2.
     
  7. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    38
    Hi Trinary,

    The validation system is on by default. It's possible to disable it in the inspector when the USS file is selected.
    The USS errors are reported as warnings in the Console window, if you don't see any it means that you're USS file is all good.

    If you're not sure you can try something unsupported like this :

    Code (CSharp):
    1. .border {
    2.  
    3. border: solid;
    4.  
    5. }