Jump to content

Guide to the Godot game engine/Resources and importing

75% developed
From Wikibooks, open books for an open world

In Godot, a Resource is an object that stores data, like Translation and Texture. They are reference-counted, which means when they are no-longer used, they will automatically delete themselves, freeing memory.

Making resources

[edit | edit source]

To make a resource, you need to first find something that will use it. Create a new scene with a Sprite2D. You can do this by pressing "Other Node" after making a new scene.

Select it and look for its Texture property. Click [empty] and press "New GradientTexture". Press the Gradient property (you may need to click on the GradientTexture) and press New Gradient from the drop-down menu. Click on this Gradient. Click the black rectangle. A blank area a little bit to the right will turn black. Click it and a popup that allows you to choose a color will appear. Choose a color. Do the same to the white rectangle. You can add more points and colours by pressing in-between any two of these rectangles. Congratulations! You made your first resource!

Games usually show art, not just square color gradients. For this, download an art program. Microsoft Paint will do for now if you use Windows, but it isn't so great when you want a transparent image (say, non-squares), so you might want a better program soon. I use Piskel. Alternatively, you could download the Godot plugin that adds an image editor. It can be found in the Asset Library (AssetLib) and enabled in Project->ProjectSettings->Plugins. I forgot the name of the image editor, however, so you might need to search around for it.

Make anything at all. A diamond, a person, a car, or just a square. Save it into your project's folder. Go back to Godot, find the file and drag it over to the Texture property of the Sprite2D in the Inspector. Congratulations! You just imported - and used - your first file!

So, wait, what did I just do?

[edit | edit source]

Importing files into your game is essential for game development. In Godot, you don't need to save the file or image into some kind of database to become usable. Just plop it down into your project's folder. Simple.

If you want to fine-tweak an imported file, do not use the Inspector! Changes made to imported resources in the Inspector won't save. Instead, double click your file, above the Scene dock is an Import tab. Press the Import tab button to show it. You will see a large or small menu depending on the file selected. For Texture (".png", ".svg", ".bmp" file extensions), you will see things like compression settings or process settings. Under Flags, uncheck Filter, then press Reimport. See any differences from your old image?

Filter makes your image look higher resolution than it actually is by making it blurry. Turning it off makes an image more pixelated.

Check Mipmaps if your image will be used in the 3D world, or show in many different sizes, to increase visual quality.

Fix Alpha Border makes your transparent images look normal when using filter or compression methods other than Lossless.

Svg Scale makes .svg files larger, scaled or higher resolution if you increase the number, with the opposite effect if you decrease the number.

What compression modes are available? And what do they do?

Compression modes and their pros and cons
Name Quality loss Loading time Performance Disk size
Lossless (default) None Slow Average Medium
Lossy High Slow Average Smallest
Video RAM Medium to High Fastest Fastest Small
Uncompressed None Medium Average Largest

The compression format you use depends on many things. In general, use Video RAM for large textures or textures you don't see up close in-game and Lossless for small textures in 2D games.

Texture artifacts are common in higher quality loss. Make sure to check your texture after re-import that it looks the same or that the quality loss is unnoticeable.

Sometimes you intend to lower the quality to break up a texture that uses flat planes of color if you are a less than skilful artist. Those artifacts can break up solid blocks of color, making it easier to make decent game art. However, consider becoming more skilled at art, or getting an artist,since this is not foolproof.

Making your own resources

[edit | edit source]
This is an example of how you can use resources in Godot 4 to create flexible and robust data storage systems. However, no functionality should be in the resource, except basic calculations based on the variables already in the resource.

You can make your own resource scripts. All they should do is hold information, they should not do any logic. For example, you can use resources to hold data for how an item works. It could store the name of the item, the image, etc. In Godot 4, it is much easier to separate different export variables in groups and drop-down menus.

In Godot 3.x, resources are mostly the same, but it is a bit more difficult to create organised groups like in Godot 4.

External links:

What you have learned

[edit | edit source]
  1. What importing is in Godot.
  2. How to make a resource.
  3. How to change the settings for an imported file.


1 What compression method is fastest to load?

2 Can lossless break up a flat plane of color?

Yes
No

3 Which of these are the best compression method?

Lossless
Lossy
VRam
Uncompressed
All of the above

4 Can you modify a texture in the Inspector?

Yes
No

5 Can gradients only have 2 colors?

Yes
No



Guide to the Godot game engine

Getting started [edit]
Installation
What is a node?
Programming
Resources and importing
Signals and methods
Your first game
Making it work
Debugging
Input
Physics
Saving and loading
Multiplayer
Making it look good
UI skinning
Animation
Advanced help
Servers (singletons)
Platform specific
Optimisation
Encryption
Exporting
Plugins
Miscellaneous
Helpful links
Authors and contributors
Print version


<-- previous back to top next -->