SVG sprites in godot?

Godot Version

4.3

Question

I’m trying to recreate a very old flash game in godot. There are certain animated cosmetic items that need to have their colors updated from code, depending what color code the user has in their inventory. Because it’s an old flash game, I only have the SWF and I can either export PNG frames, gif, canvas (broken) or SVGs.

SVGs would be a great choice because I could directly change fill properties in specific places of the item, aswell as apply color transformation rules from the original SWF asset etc. But apparently the SVG’s don’t show up in godot at all. I tried some plugins but they don’t show the SVG either.

Is there actually any way to load and work with SVGs in godot?

Godot can use SVG, and Godot icons are in SVG format

It doesn’t work though. The icon does, but the SVG I import doesn’t. I checked in browser and the SVG loads just fine

What is the size of the image you imported? There is a setting in the project settings that the image cannot exceed 2048 by default

It’s like slightly above 50 x 50

EDIT: I just tested a much simplier SVG and it worked. I guess the complexity of my SVG isn’t fully supported

Godot only supports a subset of the SVG specification, as it uses ThorVG (nanosvg in 3.x) to rasterize them. It does not support Inkscape-specific features like filters, or recent SVG 2.0 functionality like mesh gradients.

I got it to work by getting rid of some complexity that a free flash decompiler added to the SVG code when exporting the asset.

Is there any way to directly edit the SVG’s code from gdscript? If not natively, maybe with some addon? I’m basically interested in dynamically updating it’s “fill” RGB property to change color in specific parts of the SVG, at any point in the game.

It’s fine if it has to be reloaded, it will probably be unnoticable in a simple 2d game and it would only be updated when player changes their item in the inventory, or selects a color in item shop

Yes, by using String.replace() on the SVG string and using Image.load_svg_from_string() on it. You’ll need to change the SVG’s import mode to Keep (No Import) so that you can load its original text as if it was a text file and perform the runtime string replacement and loading.

See the documentation for details:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.