Search Unity

Unity Vector Graphics Preview Package

Discussion in '2D Experimental Preview' started by rustum, May 4, 2018.

  1. Rafa-Garrido

    Rafa-Garrido

    Joined:
    Feb 17, 2015
    Posts:
    1
    Hi, forum! We are now experiencing a little issue with version 2.0.0-preview.16. Some of the SVGs that we have imported in our scene show a tiny horizontal black line inside them.

    How can we fix this? We've checked out documentation, but we didn't find anything for this.

    Thanks in advance.
     
  2. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    307
    I've been having this weird issue where if you have an svg sprite in a scene, you then reimport the svg in the project settings and the prefab of the svg sprite in the scene is reset to zero (location/rotation/scale).

    Has anyone seen this issue?

    svg sprites are sort of prefabs but not right, you can't open a sprite prefab or apply any overrides to them. In the scene data the transform data is stored in modifiers.

    Looking at the scene diffs, the issue seems to be around the fileid reference to the vector. Even though the position in the scene data (viewed in text editor) is correct, in Unity it shows as zero default position once you reimport it.

    Any ideas? Thanks
     
  3. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    307
    Another question, we are using vectors in our UI canvas. What is the difference between using a Vector Sprite as the sprite in our UI SVG Image and using a UI SVGImage instead in the importer settings for generated asset? I can see the material and shader is different, I'm curious why use "ui svgimage" over "vector sprite" as the sprite used in ui elements. Thanks
     
  4. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    Not aware of that kind of issue. It's hard to tell, but if this is only occurring with a single asset, you can try playing with the tessellation settings to see if that helps.

    Also, can you try with an older version of the package to rule out a recent regression? Otherwise, you can file a bug (Help > Report a Bug...) and we'll have a look.
     
  5. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    Can you share the Unity and package version you are using? We recently fixed something similar to this in preview.15. The transform would get reset during an asset rename. Is this what you're experiencing as well? If you're still experiencing this with preview.15+ it might be worth filing a bug report.

    The "UI SVG Image" asset will pre-configure the sprite to be compatible with the UI Canvas. It will have the proper components and shaders that are compatible with the UI masking system.

    A plain "Vector Sprite" is a bit more lightweight and is designed to work with the 2D system.

    Note that in many situations, Vector Sprites will also work when used in a UI Canvas.
     
  6. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    307
    I was using 2.0.0-preview.13 and it looks like I upgraded to 2.0.0-preview.16.

    Here's exactly what was happening, its hard to file a whole project around this so I'll just describe:

    Vector graphics sprites in the scene, have position/rotation/scale/tag/layer/components added to them. Everything working well.

    Download the project into clean folder via git, those sprites have now been reset, have no pos/rotation/scale, layers/tags/components reset.

    However, if you DIFF the raw scenes files looking at the text, they are both exactly the same. Even in the scene where the vector sprites aren't showing correctly, in the scene raw text file you can see the transform data is correct.

    So I go back to my original working folder, copy the whole folder and delete the library folder, the sprites are reset.
    If I go to my working project and right click reimport those sprites, they are reset.

    My guess its something to do with the references to those objects stored in the scene not matching the same id as the current scene when it is open and something to do with how the vector sprites are prefabs (from this package), but they are not really real prefabs (just pretend ones).

    Does that make sense?

    Thanks
     
    Edan-Smith likes this.
  7. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
  8. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    307
    It's very possible, thanks. Although I didn't rename my files, but there was definitely some reference issue that was fine when I had a library folder and went wrong when I opened fresh. Will keep an eye on it, thanks
     
  9. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,007
    Is it possible to render this svg properly with the svg package?
     

    Attached Files:

  10. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    This SVG has <text> tags, which aren't supported at this time. You should have more luck by converting the text into shapes, if your vector software supports it.

    The binary digits are shapes. We can see the blue ones properly, but I'm not sure why we don't see the red ones. I'll investigate.
     
  11. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,007
    Hi Yes I have been replacing the text with TextMeshPro text. I guess I could have converted the text to paths and saved myself a bit of work.

    I was mainly the red digits mirrored I was wondering about.

    Is SVG support still being actively developed or it's in maintenance mode now?

    Thanks
     
  12. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    We are only working on fixes at this time. But we will get back to work on features on the package eventually (and also getting an official out-of-preview release).
     
  13. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    I had a second look as to why the red binary digits didn't show up. It turns out that they are there, but they get overlapped by a mask that is defined later. The com.unity.vectorgraphics package doesn't support the "mask" attribute, so the shape is displayed as a plain color instead, which hides the digits.
     
  14. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,007
    @mcoted3d Thank you for checking. I will see what I can do to work around that. I have one other strange issue. I had a svg file I was trying to import but i think it was over all too large. I split the file into two layers and then I was able to see Unity successfully import both. What is odd now I when I drag them both out the the scene only one shows up. The only difference i see is that material does not create the shader for one but does for the other. The import setting are identical as far as I can tell.

    upload_2021-6-8_16-1-25.png

    upload_2021-6-8_16-2-9.png

    upload_2021-6-8_16-4-15.png

    upload_2021-6-8_16-4-52.png
     
  15. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,007
    I just noticed this in my console log.

    upload_2021-6-8_16-8-58.png

    So Unity can import the file it is just that vertexHelper cannot?

    EDIT: So i set preserve viewport and that reduced the number of vertices used by about 10000
    buy I noticed the sprite in the scene does not match the image in the import inspector window.

    upload_2021-6-8_16-46-0.png
     

    Attached Files:

    Last edited: Jun 8, 2021
  16. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    The best way to work around this is to reduce the tessellation quality of your imported assets. You can play with the tessellation settings from the SVG asset inspector.

    Splitting your large SVG assets into multiple parts is a good idea. There is a 16 bit vertex limit for sprites that we cannot work around at this time.
     
  17. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,007
    @mcoted3d What do you think the issue might be for the last image I posted. The preview looks correct in the inspector but the image in the scene is not correct. I am still below the 16 bit vt limit i believe.
    Thank you for your assistance. :)
     
  18. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    It looks like some gradients aren't displaying properly. Try to add "TexCoord2" in the "Additional Vertex Channels" of the Canvas.
     
  19. Edan-Smith

    Edan-Smith

    Joined:
    Jan 21, 2015
    Posts:
    26
    I have a similar problem to Cochea's.

    I had to update unity from 2018.4.31f to 2019.4.28f and Vector Graphics were updated as well from 1.0.0.preview.34 to 2.0.0-preview.17.

    By doing that, ALL my SVGs that weren't set as a PNG and were in the Scene or inside Prefabs got their values reset to default... The layer, the Transform component and Sprite component as well.

    Was wondering if there is any special trick to avoid this to happen since it requires the dev to go through every single image that has SVG, compare with an older version and fix the values on each.

    I've tried re-updating a few times making little changes/tests and I didn't succeed to make a smooth transition from old to new version.

    EDIT: My temporary solution for that to not occur anymore is to copy Unlit_Vector material from the asset to an accessible folder, manually create the objects and reference the sprite directly.
     
    Last edited: Jun 13, 2021
  20. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    Interesting. Thanks for sharing. We'll try to find a different way to avoid assigning the Material from the package folder, since doing this isn't ideal.
     
  21. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,007
    Thank you for your awesome support. - that fixed it! Looking forward to further svg improvements in the future.
     
  22. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    90
    Hi, we're giving this package a try and so far it's been amazing!
    The only thing preventing us from switching from SVGImporter to this is the ability to slice (I know it's been discussed in this thread). Once the package comes out of preview, do you have a rough idea of when/if we could hope to see that feature added?
    If not, would we be able to write our own using the API?

    Thanks!
     
  23. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    307
    I'm hear from search trying to find out why sprite masking isn't working.

    If I drag the svg asset prefab into the scene and set mask interaction to visible inside/outside it doesn't work.

    I I drag in the sprite that is under the project list (within the svg asset), then the mask works fine.

    If I change the material of the svgprefab from vector unlit to sprits-default, the mask works.

    So sprite masking doesn't work with Unlit_Vector?
     
  24. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    I can't provide an ETA of if/when this feature will be implemented. Slicing makes sense in a full-rect textured quad, but is tricky to implement with a vector sprite since it's a tessellated mesh. This is hard to plug in the sprite system, but we have a semi-working version of this in UI Toolkit (see below).

    Probably. Something you can try:
    • Map the vector sprite vertices in their respective 9-slice regions.
    • Detect when the sprite is resized
    • Move the vertices so that they stay at their relative location in the 9-slice regions.
    There are probably situations where this doesn't work, especially if the vector sprite isn't finely tessellated. A similar technique was used for 9-slices in UI Toolkit, and some weird situations occurred (see https://forum.unity.com/threads/bold-font-9-slice-sorting-order.993914/#post-6717793)
     
  25. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    It should work (it works here!). There's nothing fundamentally different between Unlit_Vector and Sprites-Default. The trick is to get the "Mask Interaction" right on the Sprite Renderer component.
     
  26. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    90
    Thanks, I'll take a look, sounds pretty tricky :)
    SVGImporter supports it so I'll have a look at their code as well.

    I'm surprised slicing is not higher on the priority list, which makes me think my approach might be wrong. Isn't SVG the best way to have clean, sharp UI elements at all resolutions? From what I understand the only alternative is to provide multiple png assets at different resolutions for each UI element, or am I missing something?
     
  27. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    To be clear, it is quite high in the priority list, but major work on the com.unity.vectorgraphics package is postponed until we have better vector graphics integration with UI Toolkit. This is basically why we cannot provide an ETA at this time.

    SVGs provide can help getting good quality UI with a single asset. As you mentioned, an alternative is to provide multiple-resolution textures or mipmaps.

    One downside of SVGs is that we currently rely on MSAA for antialiasing. But we are working on an alternative antialiasing solution.
     
    Numa likes this.
  28. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    90
    Right that makes sense, thanks for clarifying!

    Beautiful. Thanks for your answers.
     
  29. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    26
    Yes, we've just hit this issue and I just did a full project reimport, losing all the scene overrides. This is a huge chunk of work that's just been obliterated. Kind of worried because we're about to release this game (I know we shouldn't be relying on preview packages, but here we are haha).

    Before reimport:


    After reimport:


    @mcoted3d This issue started for me when upgrading from 2.0.0-preview14 to 2.0.0-preview17, so it seems that it is not fixed in latest.
     
  30. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    26
    Okay, so thankfully all these references were still okay on a teammate's computer so we did a screenshare and audited each scene one at a time with him "unpacking" each of the references to importer SVG prefabs. Managed to completely work around this in 40 minutes. I'm still keen on a fix though because I suspect that our artists will still want to drag and drop SVGs into the scenes in future, which will result in breakages if we need to reimport.
     
  31. plotlessplot

    plotlessplot

    Joined:
    Sep 16, 2012
    Posts:
    12
    Hi! I'm currently using the Vector Graphics package (2.0.0-preview.17) as a base for a coloring book app that I'm working on. The goal is to import SVG files and, at runtime, detect where the user has tapped, get the tapped shape and fill it with a specific color.

    I have a couple questions regarding the correct usage of the package, as well as some performance issues:
    • At the moment, I'm generating Vector Sprites at runtime, iterating through all the layers and shapes of the SVG source file and building individual sprites (as well as attaching Polygon2D Colliders) so that I can detect user input and then alter them directly during the game. However, I'd like to know if there is any way of accessing the individual layers and shapes from a vector sprite that has already been auto-imported by the package, to avoid the potentially costly work of generating dozens to hundreds of vector sprites at runtime.
    • If I use mildly complex SVGs (e.g. a Mandala drawing), I find that the performance drops drastically the more I zoom in to the image (by zooming in, I mean changing the orthographic size of my 2D camera). I believed this was a result of increasing the mesh detail as I zoomed in, but looking at the play mode stats, the Tris and Verts counts go down, however FPS goes down as well. Is there any way to tackle this that is not lowering the quality in the tesselation settings?
    Thank you!
     
  32. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    26
    @mcoted3d hoping this is useful for debugging. So this is an example of an SVG whose transform was reset in a scene. I went back in to the scene and manually restored the position, scale, rotation. I've tracked down the section of the scene file that includes the local prefab overrides and here is the difference:

    You can see what's changed here is the
    fileID
    of the reference override:

    upload_2021-6-22_11-20-26.png

    Now I've put together the full section of YAML from the scene, and I've also included the `.svg.meta` file from the problematic asset. This meta file did not change when reimporting the file (it's unchanged since the day it was first imported).

    I don't claim to understand what the file ID means, but strangely it doesn't seem to be referenced in the SVG meta file at all! I'd actually love to understand what's going on here when you work it out, the inner workings of meta files is not well documented.

    https://gist.github.com/rhys-vdw/ab1106ba953f5739185a4446a1c238b3
     
  33. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    I don't think I've seen an official bug report for this issue. If you could open one, it would be appreciated (Help > Report a Bug...). It's not clear to me where the problem resides (is it the vector package, prefabs, or something else).

    Edit: Now thinking about it, this may be caused when going from a package <
    2.0.0-preview.15 to 2.0.0-preview.15 or later. This may change the file IDs during the reimport, but hopefully they should stay stable afterwards, I'll try to confirm this.
     
    Last edited: Jun 22, 2021
  34. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    The vector sprite is very much like a simple mesh at that point. I don't think there's an easy way to map some triangles back to the originating shape.

    I'm not sure I understand, are you re-tessellating with higher quality while zooming in? If so, that will be very slow indeed, as tessellation is very expensive. If you can tessellate once at a reasonable quality and leave it at that, you'll have much better performances. Let me know if I misunderstood something.
     
  35. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    703
    I just confirmed that this is an unfortunate side-effect of a prefab rename issue that we've fixed in preview.15. We have to assign a fileID for the transform component, so that upgrading your project from < preview.15 to preview.15 or later might break the transform during an asset reimport. However, the prefab position should persist properly afterward, even after a reimport.
     
  36. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    26
    Thanks @mcoted3d. We've gone through the tedium of auditing every prefab and instituting an "unpack on SVG placement" rule for artists. I think we're good. Given the above response I will not open an issue in the tracker.

    Huge fan of the SVG plugin btw, I'm using it in all of my games now. I eagerly await stability.
     
    mcoted3d likes this.
  37. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    307
    I had exactly the same issue as you and it took me nearly 3 days to rebuild everything, it was very frustrating.

    I now NEVER use an SVG straight in the scene, incase some issue with this asset in future. I now drag the svg on to the scene, make a parent object with the same name, save that parent object as a prefab into VectorContainers folder that mirrors my SVG folder. Then I position/scale/rotate the vectorcontainer prefab on the scene, but never the sprite directly which will always maintain a zero position/rotation/scale within the prefab.
     
    rhys_vdw likes this.
  38. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    26
    Yeah, it's brutal. It should be sufficient to simply "unpack" the SVG default sprite prefab though. I considered writing a script to recover all the data but in the end it was quicker to waste another developer's time for a couple of hours.
     
  39. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    307
    but if you unpack it, is the asset still linked if the svg is updated?
     
  40. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    26
    Yes, because the Sprite asset is still linked. It's just the prefab link that is the issue (as that contains a transform).
     
  41. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    307
    "However, the prefab position should persist properly afterward, even after a reimport."

    It doesn't, upgrading to preview 15 breaks a link in the file ID, so prefab position/rotation/scale/components are reset.

    We have a different project that is on preview 12 that we would eventually need to update, after this problem that I've had going from 12 > 16 and resetting all objects, we can't do this upgrade at the moment. Is there any way the svg asset could be patched to fix the fileID issue without loosing the prefab transformations?
     
  42. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    26
    If not it should be possible to write an editor tool that scans all prefabs and scenes, opens them, looks for an links to objects that are instances of prefabs generated from assets whose files end in .SVG and unpack them. If you do this before upgrade you should be fine. I considered writing such a tool but in the end the manual route seemed safe enough and quicker (~2 hours of two people's time).
     
unityunity