Sites


Initiation à Godot

Resources

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 some ways, resources ar a kind container that in which you put some of the assets away waiting patiently to be used. Resources can be textures, scripts, mesh, sounds, fonts, translations if your game is localized…and even scenes. Often, going deeper in node will drive to a resource at the end. For example :

  • a sprite will need a texture
  • a text (label in Godot language) 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 (until the type of resources can be handle by the node type). Data from the resources is shared among all Nodes. But as node instances have unique properties, that allow context customization,  Resources are shared among Nodes so their properties are the same everywhere. The advantage of this is will of course be optimization : as you reuse several times a loaded resource, it won’t be reloaded each time. Because properties of each copy are exactly the same, resource is just reused as is, no need to duplicate them.

We could say resources are individual contents that will be used in the game. That somewhat true but not totally exact, depending on the point of view. For example, a texture resource could have several tiles included that could be used separately by Godot tools, be they in the same file. But it is true that resources can rely on external files as well as internal objects.

The easiest example is certainly an object or player resource :

  • in Godot we will have a node for the object
  • in the inspector, we could define a texture by loading it from an external file we’d had previously copied in our project folder or subfolder. The path of this external resource won’t be referenced in Godot as /home/toto or C:/toto or whatever, because this would mean the resource location would be OS dependant. Since developer can have a different OS than (let’s say) artists, Godot does some OS path abstraction and mark it as res://myimage.png in the Resource Path property. Res is the root of our project, i.e. our project directory. In that context, just specify complete path to access the resource file, for example : res://assets/textures/myimage.png.
Notice that / are unix style in the paths

The FileSystem panel shows all the project resources in list or preview mode (useful for textures and sprites). Another nice tool of this window is the view Owner option which list each file in which this resource is used. Very practical when deep changes are made or control need to happen.

Resources are reference counted. As long as a reference is maintained, 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 do this, 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.

The resource being an external file, it is dynamically loaded by Godot. So that modifying the file on disk will immediately modify it in the game. Each artist, coder, level designer can so work on his own without interferring with others.

Of course resource can be loaded from GUI but from code too. In both cases, it needs to be in the project directory and will be available by res:// root.

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.