Sites


Godot Game Engine

Resources

Resources are Objects that contain the data of the game. Compared to nodes, they won't provide any action but they will keep our contents available for the game. In a way, resources are a kind container that stores the assets in a way that is optimized for runtime usage. Resources can be textures, scripts, meshes, sounds, fonts, translations if your game is localized, and even scenes. Often, most nodes will rely to some extent on resources, e.g.:

  • a sprite will need a texture,
  • a label will need a font,
  • a 3D player will have a mesh object and textures,
  • the player itself will be connected to scripts to handle its behavior.

Resources are shared between nodes so that you may reuse them all over the game without restriction (provided the type of resources can be handled by the node type). Contrarily to node instances which have unique properties for customization, Resources are shared among nodes so their properties are the same everywhere. The main advantage of this is of course performance optimization: when you reuse a loaded resource several times, it will not have be reloaded each time. Since the properties of each copy are exactly the same, the resource is just reused as is, without having to be duplicated first.

Resources can be embedded directly in the scene file when their format is compatible, or saved externally in the project filesystem. Some resources can also be loaded directly from the filesystem without having to be converted to an internal format, for example PNG images or OGG music files.

FileSystem

To reference external resources that are not embedded in the scene file, Godot uses a virtual filesystem with the prefix res://. It is defined relatively to the main project folder (the one containing the engine.cfg files that defines a project), and can be used to access all resources within this folder and its subfolders. It is necessary as using system absolute paths would not be cross-platform (e.g. /home/user/myproject on Linux would not match C:\Godot\MyProject on Windows), and obviously different developers and users would likely not have the exact same absolute paths either even on the same OS.

Note that Godot's filesystem uses Unix-like folder delimiters in paths (/), so even on Windows you would access an image with e.g. res://assets/sprite/floss-hero.png.

In the editor, the FileSystem panel shows all the project resources in list or preview mode (useful for textures and sprites). Another useful tool of this panel is the "View Owners" option which lists each file in which this resource is used.

    

Resources are reference counted. As long as a reference is maintained, the resource is not deleted. If you delete or remove the resource file from its folder, the texture won't be available anymore unless you have packed it in your scene. To remove the reference, just delete the path in the resource property of the Inspector and it's done.

Of course, keeping resources external makes it easier to improve them as the game development progresses. If the resource is in an external file, it is dynamically loaded by Godot. Modifying the file on disk will therefore immediately modify it in the game (a scene reload might be needed though to see the changes applied). Each artist, coder or level designer can therefore work on their own without interfering with others. Resources can be loaded both from the editor GUI or from the code. In both cases, it has to be in the project directory to be accessible from the res:// filesystem.

Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.

Vous devriez rafraîchir la page.