How to Implement Custom User Sprites

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WarDev

Hi All!

I am currently trying to implement a system where the user can easily create and use their own custom sprites for my game, I.E. they can drag and drop their own folder with a particular set of images with particular names and have that appear in the game.

I initially just tried to load each of the images the user provided for the sprite using the plain old “load” function. This didn’t work, presumably because the user provided images aren’t properly imported into godot.

I fiddled around with the code a little bit and then tried the following method:

				var imageImport =
				var animationImageTexture =
				# Adding the frame to our animation at the correct location
                animationImageTexture, animationFrame)

This worked, and I tested it on a fresh machine, and I was able to provide custom user sprites on the new computer and it worked like a charm. However, allowing the user to provide their own sprite images caused a lot of nearly identical warnings to appear in the debugger. This is an example of a warning I received:

load: Loaded resource as image file, this will not work on export: 'res://Packages/Default/Player/Graphics/legs/default/0.png'. Instead, import the image file as an Image resource and load it normally as a resource.
  <C++ Source>  core/image.cpp:1890 @ load()
  <Stack Trace> @ loadAnimation()
       @ loadAnimations()
       @ init()
       @ init()
       @ init()
       @ init()
       @ _ready()

This is concerning to me both in that I may have done something wrong that will cause issues for me down the line and because the debug warning messages cause a notable slow down (about 7-8 seconds) in the startup time of the game in the editor. Outside of the editor it is fine.

Does anyone know if I’m doing something harmful here, if there is another, better way I could accomplish what I want to accomplishment, and finally, if what I’m doing is the best way to do this, does anyone know if I can suppress these warnings?

:bust_in_silhouette: Reply From: rakkarage

to fix error message
set the type to image in import setting and load like this

var image: Image = load("res://PixelLevel/Sprite/Template/BasicBack.png"),
:bust_in_silhouette: Reply From: JimArtificer

That warning looks like it is telling you that the images you loaded that way won’t be bundled when you export the game for release. But you shouldn’t have to worry about that since the point is to load user images.

The performance issue is more concerning. Perhaps there is a way you can disable that warning with an optional parameter or config variable.