23 lines
1.5 KiB
Markdown
23 lines
1.5 KiB
Markdown
|
|
## Resources
|
|
|
|
Resources are essentially data containers.
|
|
Much like nodes, they can hold functions, properties, and signals.
|
|
|
|
Resources do nothing on their own. They must be a property of a node for their data to be accessed.
|
|
|
|
The resoource only gets loaded into memory once. Any nodes referencing a node are accessing the SAME data. This behavior can be changed so that the resource is unique for each node referencing it.
|
|
|
|
## Autoload Singletons
|
|
|
|
The scene system in Godot is great for building multiple levels of a game and being able to run each one of them individually during development. However it does have a limitation.
|
|
|
|
When a scene is reloaded, or another scene is loaded in its place, all information is lost. This can be problematic for gameplay, because it means that variables storing information such as player health, number of enemies, etc. are lost when the scene is reloaded.
|
|
|
|
One answer to this is the use of an Autoload resource.
|
|
|
|
An autoload resource is one that can be specified in the project settings. It will be loaded ahead of all other resources, and can be given a name that can be referenced throughout the game by any other code. Data in this autoloaded resource will persist across scene changes.
|
|
|
|
An autoload script is a good place to put any persistent game logic and data, as well as any helper methods that may be useful to a wide variety of nodes in your game.
|
|
|
|
It is possible that an autoload script can get quite cluttered with information, so a good combination is to use an autoload script and data objects together. |