Skip to main content
Resources are the foundation of Godot’s data storage system. They serve as serializable containers for data and assets, from textures and sounds to custom game data and scene files.

What is a Resource?

A Resource is the base class for all Godot-specific resource types. Resources are reference-counted objects that can be saved to disk, loaded, and shared between multiple nodes. They inherit from RefCounted, which means they’re automatically freed when no longer referenced.
Resources are primarily data containers. Unlike nodes, they don’t have a position in the scene tree and don’t receive processing callbacks.

Common Resource Types

Godot includes many built-in resource types:
  • PackedScene: Stores a complete scene hierarchy
  • Texture2D: Image resources for sprites and UI
  • AudioStream: Sound and music files
  • Material: Shader and rendering properties
  • AnimationLibrary: Animation data
  • Script: GDScript, C#, and other script files
  • Theme: UI styling information

Loading Resources

There are several ways to load resources in Godot:

Using preload()

preload() loads resources at compile time:
Use preload() for resources you know you’ll need immediately. The path must be a constant string literal.

Using load()

load() loads resources at runtime:

Using ResourceLoader

For more control over loading:
The engine maintains a global cache of loaded resources. The same resource path will return the same resource instance, saving memory but potentially causing unexpected shared state.

PackedScene

PackedScene is a special resource type that stores an entire scene hierarchy:

Instantiating PackedScenes

Creating PackedScenes

You can create PackedScenes programmatically:
Only nodes with their owner property set will be saved when packing a scene. This prevents temporary or runtime-generated nodes from being saved unintentionally.

Saving Resources

Use ResourceSaver to save resources to disk:

Custom Resources

You can create your own resource types for game data:
Using custom resources:
Custom resources provide several benefits:
  1. Data Separation: Game data is separate from game logic
  2. Reusability: The same resource can be used by multiple nodes
  3. Editor Integration: Can be edited in the Inspector
  4. Serialization: Automatically saved and loaded with scenes
  5. Type Safety: Define clear data structures with type checking

Creating Resource Files

You can create resource files in the editor or via code:

Resource Properties

Resource Path

Every resource has a path indicating where it’s stored:

Resource Name

Local to Scene

The resource_local_to_scene property makes each scene instance get its own copy:
When resource_local_to_scene is true, each scene instance gets a duplicate of the resource. This is perfect for data that should be instance-specific.

Resource Duplication

Resource Signals

Resources can emit signals when they change:
The changed signal is not emitted automatically for custom resources. You must call emit_changed() manually in your setters.

Practical Example: Inventory System

Here’s a complete example using custom resources:

Resource Preloading Best Practices

1

Use preload() for Essential Resources

Preload resources that are needed immediately at startup:
2

Use load() for Optional Content

Load resources dynamically when they might not be needed:
3

Consider Resource Pooling

For frequently instantiated scenes, maintain a pool:

Best Practices

1

Use Custom Resources for Game Data

Create custom resource types instead of using Dictionaries or hard-coded values.
2

Set Ownership When Packing Scenes

Always set the owner property on nodes you want to save in PackedScenes.
3

Leverage resource_local_to_scene

Use this property for resources that should be unique per scene instance.
4

Emit changed Signal

Call emit_changed() in custom resources when data changes to notify dependents.
5

Be Mindful of Resource Caching

Remember that loaded resources are cached. Modifications affect all users of that resource.

Next Steps

Nodes and Scenes

Learn how nodes use resources

Scene Tree

Understand scene management