# SVG Asset Importer

**URL:** <https://forums.unrealengine.com/t/svg-asset-importer/83956>\
**Category:** Game Development\
**Tags:** unreal-engine\
**Created:** [January 29, 2017, 4:04pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956 "2017-01-29T16:04:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [January 29, 2017, 4:04pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/1 "2017-01-29T16:04:10Z")

</div>

## Get it now [on the marketplace](https://www.unrealengine.com/marketplace/svg-importer-plugin) or [on Gumroad](https://gumroad.com/l/JeRcF)!

Since I use SVGs a lot and UE4 does not support them natively, I thought it would be a good idea to write my own importer 🙂  
Besides from creating textures from the SVGs, the plugin also allows to import them as distance fields, to create sharp masks in a material.  
See the video for a demonstration:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/d/1/4d1c0be87ea5e155a87f82b63e7c6584b60df891.jpeg "SVG to Texture Plugin (UE4)") ](https://www.youtube.com/watch?v=MvokfyihNXs)

Here is an example how the distance field importer works, the resulting texture has **only 85 kB** :

 ![Screenshot03-min.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/3/b3865cc77fefc372e00586227c4f18de84e9444f.png)  
 ![Screenshot03-min.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/3/b3865cc77fefc372e00586227c4f18de84e9444f.png)

---

<div class="post-metadata">

**Author:** ![Dannington](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannington](https://forums.unrealengine.com/u/Dannington)\
**Post date:** [January 31, 2017, 3:32pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/2 "2017-01-31T15:32:22Z")

</div>

This is great! Nice work - distance fields are a bit black magic for me though - how in the blazes do they work?

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [January 31, 2017, 3:54pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/3 "2017-01-31T15:54:16Z")

</div>

> [@Dannington;659036](#):
>
> This is great! Nice work - distance fields are a bit black magic for me though - how in the blazes do they work?

Thanks! 🙂  
[This paper from Valve](http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf) has is a very good explanation how they work. The multichannel part just takes the idea one step further and uses not just a greyscale image, but rather all colors to pack more information into the distance field (Valve also mentions this on the last page of their paper). This allows for example sharp corners in the result.

Usually you would need a custom shader to convert the distance field back into a useable mask, but luckily EPIC already provides a “DistanceField” node in the material editor (as you can see in the screenshot). This is because they use the same technique to cache fonts you want to use in your game (because recreating a font character from a distance field is a lot cheaper than drawing it from its TTF outlines).

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [March 16, 2017, 8:39pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/4 "2017-03-16T20:39:56Z")

</div>

The plugin is finally available on the marketplace! 😃

> **[SVG Importer Plugin in Code Plugins - UE Marketplace](https://www.unrealengine.com/marketplace/en-US/product/svg-importer-plugin)**
>
> This code plugin allows the editor to import SVG (scalable vector graphics) files as rasterized rendering or as (multi-channel) signed distance field.

---

<div class="post-metadata">

**Author:** ![VICOGameStudio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VICOGameStudio](https://forums.unrealengine.com/u/VICOGameStudio)\
**Post date:** [March 20, 2017, 8:39pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/5 "2017-03-20T20:39:44Z")

</div>

Really cool plugin! Well done.

I have some questions:

1. Is color data taken from the SVG as well? For gradients, for example.
2. Are non-square SVGs supported for distance field creation?

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [March 21, 2017, 8:10am UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/6 "2017-03-21T08:10:54Z")

</div>

> [@VICOGameStudio;683430](#):
>
> Really cool plugin! Well done.
> 
> I have some questions:
> 
> 1. Is color data taken from the SVG as well? For gradients, for example.
> 2. Are non-square SVGs supported for distance field creation?

Thank you 🙂

1. SVG color information is only taken into account if the SVG is imported as rasterized rendering. For distance fields only the SVGs path information is used.
2. I don’t know what you mean with non-square SVGs. The SVG paths are autoframed (scaled and moved) to completely fill a square texture object, but the SVG shapes/paths do not have to be squares themselves.

---

<div class="post-metadata">

**Author:** ![VICOGameStudio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VICOGameStudio](https://forums.unrealengine.com/u/VICOGameStudio)\
**Post date:** [March 21, 2017, 2:57pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/7 "2017-03-21T14:57:46Z")

</div>

> [@Cultrarius;683604](#):
>
> Thank you 🙂
> 
> 1. SVG color information is only taken into account if the SVG is imported as rasterized rendering. For distance fields only the SVGs path information is used.
> 2. I don’t know what you mean with non-square SVGs. The SVG paths are autoframed (scaled and moved) to completely fill a square texture object, but the SVG shapes/paths do not have to be squares themselves.

1. I see, ok.
2. Hmm, strange. Because we had tried it with a non-square SVG, an elongated graphic, and only the first quarter was put into the distance field texture. Any idea? I edited your source to see if creating/generating non-square distance field textures is possible and it works pretty well. There is only a small artifact I can’t yet figure out.
3. How would I go about adding an outline? From the Valve paper, it seems that checking the value after all of the min/max nodes and seeing if it’s between a set threshold is the way. Is that correct here as well?

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [March 21, 2017, 5:32pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/8 "2017-03-21T17:32:57Z")

</div>

> [@VICOGameStudio;683740](#):
>
> 1. I see, ok.
> 2. Hmm, strange. Because we had tried it with a non-square SVG, an elongated graphic, and only the first quarter was put into the distance field texture. Any idea? I edited your source to see if creating/generating non-square distance field textures is possible and it works pretty well. There is only a small artifact I can’t yet figure out.
> 3. How would I go about adding an outline? From the Valve paper, it seems that checking the value after all of the min/max nodes and seeing if it’s between a set threshold is the way. Is that correct here as well?

If you have a shape that you think should work but does not, feel free to [EMAIL=“[cultrarius@posteo.de](mailto:cultrarius@posteo.de)”]send it to me and I will have a look at it. SVGs can be surprisingly complex and I could not test every possibility before releasing the plugin. I also plan to improve arc support for the plugin, because the current implementation does not seem to handle them correctly.

As for the outline: that is a great idea that I did not consider before, thanks 🙂  
But I just tested it and it works exactly as you said!  
See the following material, as you increase the “Outline Threshold” parameter, the thickness of the outline increases. The thickness of the outline is also largely dependent on the “Pixel Range” import parameter - larger values create thicker outlines.

 ![MSDF_Outline_Mat.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/9/596101fe9fe66837e5fa7161c5dc603c8488dc0b.jpeg)

---

<div class="post-metadata">

**Author:** ![VICOGameStudio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VICOGameStudio](https://forums.unrealengine.com/u/VICOGameStudio)\
**Post date:** [March 21, 2017, 6:47pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/9 "2017-03-21T18:47:12Z")

</div>

Sent you an email with the SVG in question.

Ah, perfect! The outlines only go inwards though, correct? They don’t add onto the outer edge?

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [March 22, 2017, 8:12am UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/10 "2017-03-22T08:12:20Z")

</div>

> [@VICOGameStudio;683861](#):
>
> Ah, perfect! The outlines only go inwards though, correct? They don’t add onto the outer edge?

Yes, exactly, they only go inwards. Also, after a certain thickness, all kinds of render artefacts start to appear, so it is only applicable for small outlines.

---

<div class="post-metadata">

**Author:** ![0lento\_archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@0lento\_archive](https://forums.unrealengine.com/u/0lento_archive)\
**Post date:** [March 27, 2017, 6:00pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/11 "2017-03-27T18:00:03Z")

</div>

Besides outlines, you can easily do drop shadows too with distance fields. That Valve paper linked here earlier had example for that too. You basically just offset the same distance field a bit and draw the shadow if the main shape isn’t drawing anything there already 🙂

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [April 1, 2017, 8:14am UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/12 "2017-04-01T08:14:59Z")

</div>

> [@0lento;686597](#):
>
> Besides outlines, you can easily do drop shadows too with distance fields. That Valve paper linked here earlier had example for that too. You basically just offset the same distance field a bit and draw the shadow if the main shape isn’t drawing anything there already 🙂

That is also a great idea 🙂  
Here is an example material that achieves this effect:

 ![TX4mB8t.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/1/41dfead73a43cdf058de13724a33c714f60431bf.jpeg)

Also, one user noticed that UI materials may create pixelized icons when used with very small icons. The solution is to increase the edge softness, but that of course makes the large icons look blurry.  
His solution is to adjust the edge softness with this addition to the material:

![e196b969a96588e69928a35a1d6b290cc7006b16.jpeg](https://d1ap1mz92jnks1.cloudfront.net/images/transparent.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_db3795de](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_db3795de](https://forums.unrealengine.com/u/anonymous_user_db3795de)\
**Post date:** [July 31, 2017, 7:58am UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/13 "2017-07-31T07:58:47Z")

</div>

Hi, am looking at getting into UE and came across your plugin. I’m trying to understand if your import process treats SVGs as actual vector objects, or is the content converted to bitmap once imported? Is it only when the imported object is used as a mask that you get the value of the vector data?

I’m asking because I’ve spent a long time looking for a reasonably priced game development tool that supports display of real vector objects (and is able to colorize/affect them via script or code). The game I’m looking to do relies on a lot of primitive shape assets that need to scale and recolor, and building them all as images would seemingly be inefficient.

Thanks in advance for your response!

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [August 22, 2017, 1:47pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/14 "2017-08-22T13:47:06Z")

</div>

> [@netdzynr7;743744](#):
>
> Hi, am looking at getting into UE and came across your plugin. I’m trying to understand if your import process treats SVGs as actual vector objects, or is the content converted to bitmap once imported? Is it only when the imported object is used as a mask that you get the value of the vector data?
> 
> I’m asking because I’ve spent a long time looking for a reasonably priced game development tool that supports display of real vector objects (and is able to colorize/affect them via script or code). The game I’m looking to do relies on a lot of primitive shape assets that need to scale and recolor, and building them all as images would seemingly be inefficient.
> 
> Thanks in advance for your response!

During the import process, the SVG is rendered as image - so there is no way to access the SVG information at runtime. If you choose to import the SVG as distance field (probably what you mean with ‘mask’) then you get several benefits: very small texture sizes and infinite up-scaling with sharp edges. The disadvantage is that does not work well for complex shapes, but for simple shapes it is perfect.

---

<div class="post-metadata">

**Author:** ![annuschka](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@annuschka](https://forums.unrealengine.com/u/annuschka)\
**Post date:** [November 12, 2017, 3:45pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/16 "2017-11-12T15:45:59Z")

</div>

(I deleted my other, now obsolete, post)

I had problems to find the Distance Field Nodes you used in your Screenshots. But in the meantime I figured it out and want to share the process with everyone else:

- “DistanceField” Node: It does not pop up in the palette (nor in the Documentation at all), because it is an Editor Material Function that has “Expose to Library” set to OFF. To get it: In the content browser click on view options, enable Engine Content. Go to EngineContent/Functions/Engine\_MaterialFunctions01/Texturing/DistanceFields Open it, click on the free grid space, look at the Details panel and check “Expose to Library”. Now you can find it easily when building your material.

- The “DistanceFieldTexture” node is just a TextureSample as Parameter and named like this. \<rant\> For newbies like me, this is always confusing when trying to follow UE4 docs or tutorials oO\</rant\>

I did play around with some sample Distance Fields I snatched from google image search and: Settings on the material and the file itself are not _that_ important. Works with different material domains as well as default image import settings (… not using specialized settings like VectorDisplacementMap).  
And while I’d really like to see native SVG support (and realtime path modification) your Plugin and the SDFs format open up fun ways to display stuff:  
I quickly put in some sine and noise with a nice result:

---

<div class="post-metadata">

**Author:** ![duke22](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@duke22](https://forums.unrealengine.com/u/duke22)\
**Post date:** [November 13, 2017, 3:57am UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/17 "2017-11-13T03:57:07Z")

</div>

Eagerly awaiting 4.18 compatibility…

For whatever reason it’s not reading this:

> **[WeaponAmmunition\_HEBullet.svg](https://www.dropbox.com/s/scbtslczlysw9l0/WeaponAmmunition_HEBullet.svg?dl=0)**
>
> Shared with Dropbox

---

<div class="post-metadata">

**Author:** ![PlayingKarrde](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PlayingKarrde](https://forums.unrealengine.com/u/PlayingKarrde)\
**Post date:** [November 24, 2017, 7:46pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/18 "2017-11-24T19:46:44Z")

</div>

Also not seeming to get any result from my SVG when brought in as a distance field. Assuming it’s 4.18 compatibility…? (First time trying the plugin so I can’t be sure)

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [December 12, 2017, 8:25pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/19 "2017-12-12T20:25:24Z")

</div>

> [@duke22](#):
>
> Eagerly awaiting 4.18 compatibility…
> 
> For whatever reason it’s not reading this:  
> [Dropbox - WeaponAmmunition\_HEBullet.svg - Simplify your life](https://www.dropbox.com/s/scbtslczlysw9l0/WeaponAmmunition_HEBullet.svg?dl=0)

Hey, the wait is over, 4.18 is released! 🙂

As for your SVG problem, the “RGBA rendering” works as intended:

 ![RGBARender.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/3/93983d474afa460613bb127d382be45e257b8e51.png)

But you probably want to import it as distance field texture:

 ![DistanceField.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/d/fddd7b2226439c0681e3264459a80f2cd143308c.png)

This leads to an import error which says that the renderer cannot process your SVG paths (which can have any number of reasons), but it also suggests a solution:

 ![MSDF_ImportError.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/3/83b8227505ac641326983327520e3963d1e53db4.png)

To do that, you have to check the “Convert All Elements to Path” option in the import dialog:

 ![ConvertToPath.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/1/5113d9bc066e4b54d2918acd883b0dfb6460da44.png)

This allows you to import the SVG, but as you can see there are some artefacts and the explosion is messed up:

 ![Converted.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/7/07de9e80af2e089e9c2223f5453a58b1132f5dbd.jpeg)

The problem is you have too many contours in your SVG. The renderer “fills” every closed shape, but if you stack shapes onto one another then it creates a hole in the shape. You are stacking a lot of unnecessary shapes onto each other:

 ![Contours.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/5/c502ea9e2b8e291bea3a76b2ad6b7c95738a6044.png)

So, after a little bit of cleaning the SVG up in Inkscape by removing the unnecessary shapes, it can be imported rather nicely (at least the bullet):

 ![CleanedUp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/5/b564f84335f6da6eae5e54c70da47da3f8801add.jpeg)

As you can see, the explosion still creates artefacts, because there are too many overlapping shapes. I hope this helps you to create SVGs which can be nicely imported 🙂

---

<div class="post-metadata">

**Author:** ![Cultrarius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cultrarius](https://forums.unrealengine.com/u/Cultrarius)\
**Post date:** [December 12, 2017, 8:30pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/20 "2017-12-12T20:30:42Z")

</div>

> [@annuschka](#):
>
> (I deleted my other, now obsolete, post)
> 
> I had problems to find the Distance Field Nodes you used in your Screenshots. But in the meantime I figured it out and want to share the process with everyone else:
> 
> - “DistanceField” Node: It does not pop up in the palette (nor in the Documentation at all), because it is an Editor Material Function that has “Expose to Library” set to OFF. To get it: In the content browser click on view options, enable Engine Content. Go to EngineContent/Functions/Engine\_MaterialFunctions01/Texturing/DistanceFields Open it, click on the free grid space, look at the Details panel and check “Expose to Library”. Now you can find it easily when building your material.
> 
> - The “DistanceFieldTexture” node is just a TextureSample as Parameter and named like this. \<rant\> For newbies like me, this is always confusing when trying to follow UE4 docs or tutorials oO\</rant\>
> 
> I did play around with some sample Distance Fields I snatched from google image search and: Settings on the material and the file itself are not _that_ important. Works with different material domains as well as default image import settings (… not using specialized settings like VectorDisplacementMap).  
> And while I’d really like to see native SVG support (and realtime path modification) your Plugin and the SDFs format open up fun ways to display stuff:  
> I quickly put in some sine and noise with a nice result:

Huh, they must have changed that in 4.17 or 4.18 then - thank you for the great writeup!  
Just as a hint, you can also just import and use one of the materials used in the example project [SVGImporterExamples.zip - Google Drive](https://tinyurl.com/SVGImporterExamples) 🙂

---

<div class="post-metadata">

**Author:** ![Roi\_Danton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Roi\_Danton](https://forums.unrealengine.com/u/Roi_Danton)\
**Post date:** [May 11, 2018, 4:20pm UTC](https://forums.unrealengine.com/t/svg-asset-importer/83956/21 "2018-05-11T16:20:27Z")

</div>

Basic question about Signed Distance Fields Texture (I only have a very rough idea about how sdf work) - when import SVGs that contain colors or gradients as signed distance field, those colors/gradients won’t be imported?

[Next page](https://forums.unrealengine.com/t/svg-asset-importer/83956.md?page=2)
