I think the title is self explanatory. I need to use a svg file as a sprite in unity, namely UI. How?
Sprites are based on textures and bitmaps, which are fundamentally different from SVGs and vector graphics. E.g. sprites have a fixed pixel size, whereas SVGs are resolution independent.
Depending on what you want to do, converting the SVGs in an external editor to PNG and then importing those PNGs as sprites into Unity might be the best approach.
Unity does have a vector graphics package that you can use to import SVGs directly into Unity. You’ll end up with a vector graphics asset and corresponding components to use those assets instead of a sprite, though. E.g. for uGUI you have SVGImage instead of the sprite-based Image
.
Note that the package is experimental and currently not actively developed aside from important bug fixes:
The Vector Graphics package is considered experimental and is not recommended to be used in production. Therefore, the package must be added using the com.unity.vectorgraphics name as described in the Unity Package Manager manual.
There are also methods like VectorUtils.BuildSprite or VectorUtils.GenerateAtlas that allow you to render vector images into sprites or textures. But doing so is more low-level and pretty cumbersome, so that’s more for very specific use cases.
Looking for something similar but no idea, found this though, take a look and see if it works → Unity UI SVG support script