0 votes

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 = Image.new()
                imageImport.load(currentFilePath)
                var animationImageTexture = ImageTexture.new()
                animationImageTexture.create_from_image(imageImport)

                # Adding the frame to our animation at the correct location
                getSpriteFrames().add_frame(animationString, 
                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> WarSprite.gd:87 @ loadAnimation()
                WarSprite.gd:57 @ loadAnimations()
                WarSprite.gd:37 @ init()
                Actor.gd:9 @ init()
                Player.gd:9 @ init()
                WarScene.gd:21 @ init()
                TestScene.gd:20 @ _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?

asked Jul 15 in Engine by WarDev (21 points)

2 Answers

0 votes

to fix error message
set the type to image in import setting and load like this
https://docs.godotengine.org/en/stable/getting_started/workflow/assets/importing_images.html

var image: Image = load("res://PixelLevel/Sprite/Template/BasicBack.png"),
answered Jul 15 by rakkarage (1,113 points)
0 votes

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.

answered Jul 16 by JimArtificer (852 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.