Search Unity

Feature Request Gradients

Discussion in 'UI Toolkit' started by Nexer8, Mar 8, 2021.

  1. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    Any plans for gradients? Some types I can think of are linear(Directional) and 4 corner gradient. Gradients seem to be in again in the UI world and I think UI Toolkit could need this feature.
     
  2. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    377
    It's not on our short term TODO list, but we understand it would be a useful feature. At the moment, one way to achieve this is by using an SVG asset or the Mesh API.
     
    Nexer8 likes this.
  3. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    Interesting, but how do you link an SVG to a Visual Element, and can you generate SVGs yourself?
     
  4. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    377
    The SVG package allows to import SVG assets, which can then be used with UIToolkit. The resulting vector image can be assigned to an Image element.

    Regarding vector image generation, we're working on a Vector API that you could use directly inside generateVisualContent, but gradients are not planned for this first iteration though. Otherwise the SVG package contains APIs to define a vector scene but I'm not sure if it's available at runtime. I'll poke the main dev of that package so he can give you a more detailed answer.
     
    mariandev and Nexer8 like this.
  5. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,003
    The VectorScene API from the vector graphics package is available at runtime. However, we lack the required APIs to generate UI Toolkit-compatible VectorImages at runtime, this part is only available in the editor for the SVG importer. This gap should be resolved eventually, but I can't provide an ETA.
     
    mariandev and Nexer8 like this.
  6. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    Ok, so if I get this right; Currently I can use SVGs for UI Toolkit runtime, but not Vector Scenes, which are procedural vector elements?
     
  7. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,003
    Correct. You can use VectorScene can dynamically generate 2D sprites at runtime, but you won't be able to generate UI Toolkit assets (VectorImage) at this time.

    A workaround would be to dynamically create a VectorScene with a gradient, then create a sprite from it (using VectorUtils.BuildSprite), and convert it to a texture (using VectorUtils.RenderSpriteToTexture2D). This a quite heavy workflow, but the resulting texture could be used by UI Toolkit.

    VectorUtils docs:
    https://docs.unity3d.com/Packages/c...2.0/api/Unity.VectorGraphics.VectorUtils.html
     
    Nexer8 likes this.
  8. MoruganKodi

    MoruganKodi

    Joined:
    Feb 11, 2015
    Posts:
    79
  9. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    I'd like to throw in another vote for this. Gradients are much more important in game UI than web UI. For example, a quick browse of https://www.gameuidatabase.com/ shows roughly 75% of them have some sort of gradients going on, although many are fairly subtle or to provide depth.
     
    mariandev likes this.