NEVER Do in Resource Design
- NEVER modify resource instances directly β Without
.duplicate(), changing a value (like HP) modifies the shared.tresfor everyone. - NEVER use untyped arrays in Resources β
@export var items: Arrayallows logic errors. Always useArray[ResourceClass]for type safety. - NEVER store Node references in Resources β Objects that only exist in a specific SceneTree cannot be serialized. Store
NodePathorUID. - NEVER perform heavy calculations in Resource getters/setters β Resources should be data containers. Offload logic to Nodes or specialized RefCounted classes.
- NEVER skip
ResourceSaver.save()error checks β Saving can fail due to permissions, disk space, or path issues. Always check the return code. - NEVER use Resources for high-frequency runtime data β If a value changes 60 times a second (like velocity), a standard variable is faster than a Resource property.
- NEVER allow circular Resource references β If A.tres references B.tres and B.tres references A.tres, the engine may crash on load.
- NEVER forget the
_initdefaults β Resources created vianew()or in the Inspector need default values in their constructor to be editable. - NEVER share a Resource between entities if they need unique state β Use
resource_local_to_scene = trueorduplicate()for components. - NEVER use
.tresfor massive datasets β If you have 10,000 items, a JSON or custom binary format might be more efficient than individualized Resource files.
Decision Tree: Resource vs RefCounted vs Node
| Type | Use when | Disk / Inspector |
|---|---|---|
Resource |
Shared definitions, saveable data, @export authoring |
.tres/.res, Inspector β
|
RefCounted |
Temporary runtime calcs, non-persistent helpers | No disk / weak Inspector |
Node |
Scene entities with process/signals in the tree | Scene files |
Use Resources for: item defs, stats templates, abilities, dialogue tables, enemy configs. Use RefCounted for: damage calc scratchpads, ephemeral state machines, non-saved utilities.
Available Scripts β MANDATORY by Scenario
| Scenario | MANDATORY read |
|---|---|
Per-instance mutable stats (HP) sharing a base .tres |
resource_local_to_scene.gd |
| Nested Item β Weapon β StatusEffect trees / save whole graph | nested_resource_serialization.gd |
| Many entities sharing one config (flyweight) | resource_flyweight_caching.gd / flyweight_enemy_config.gd |
Custom @export data containers |
custom_data_resource.gd |
| Reactive stats with signals | character_stats_resource.gd |
| Inventory arrays of Resources | resource_based_inventory.gd |
| Save Resource trees to disk | resource_save_system.gd β check Error |
| Preload / O(1) cache before play | resource_preloading_strategy.gd |
Runtime Resource.new() loot |
dynamic_resource_generation.gd |
| Validate / pool / factory | resource_validator.gd / resource_pool.gd / data_factory_resource.gd |
Expert WHY (critical)
CAUTION: Runtime HP/mana on a shared
.treswithoutduplicate(true)orresource_local_to_scenemutates the asset on disk β the "damaging one damages all" bug.
.resvs.tres: binary.resin production;.tresfor design diffs; nested trees save with parent viaResourceSaver.- Cache:
ResourceLoader.CACHE_MODE_REPLACEafter external edits bypass stale cache. - Local-to-scene / duplicate: mandatory for per-instance components β resource_local_to_scene.gd.
- 10k+ rows: individualized
.tresfiles lose to JSON/binary β see Official Docs binary serialization.
Deep dive (load on demand)
Pattern 1β7 walkthroughs (ItemData, databases, RefCounted calcs, directory scan, O(1) cache) β references/resource-patterns-deep.md. Implement nested weapons from nested_resource_serialization.gd, not memory.
Reference
Progressive disclosure: open Official Documentation links only when researching a specific API; load Related Skills when routing to a peer domain β do not preload the whole lattice.
Official Documentation
- Resources β Custom Resource scripts,
.tres/.res, sharing vsduplicate(), andresource_local_to_scenefor per-instance state. - Data preferences β When to store data in Resources vs dictionaries, ConfigFile, or plain scripts for inspector and serialization needs.
- Resource β
duplicate,emit_changed,resource_path, and local-to-scene flags used by every data container pattern here. - ResourceLoader β Cached
load/ threaded requests that power flyweight sharing and preload caches. - ResourceSaver β Persist custom Resources to
user://orres://and always check the returnedError. - RefCounted β Lightweight runtime objects when you need refcounting without disk serialization or Inspector exports.
- Saving games β Broader save strategies that pair with ResourceSaver for slot-based
.tresstate. - Background loading β Threaded
ResourceLoaderpolling so databases and VFX packs do not hitch the main thread. - GDScript exports β Typed
@export/Array[T]so item and quest Resources stay Inspector-safe. - Binary serialization API β Compact FileAccess packing when thousands of rows outgrow individualized
.tresfiles. - Scene organization β Why shared Resources live outside scene trees and how component scenes compose exported data.
Related Skills
Prerequisites
- godot-project-foundations β Project layout, import, and
res://hygiene before authoring shared.tresdatabases. - godot-gdscript-mastery β
class_name, typed arrays, setters, and@tooldiscipline every custom Resource script depends on.
Complements
- godot-signal-architecture β Ownership and fan-out for Resource
changed/ custom signals that drive reactive UI and stats. - godot-save-load-systems β Slot versioning, migration, and secure paths that wrap ResourceSaver/ResourceLoader save flows.
- godot-scene-management β Packed scenes and threaded loads that consume preloaded Resource caches without hitch spikes.
- godot-ability-system β Ability/buff definitions are Resource data; this skill owns the container and serialization patterns.
- godot-dialogue-system β Dialogue graphs and line tables are nested Resources that reuse typed-array and save patterns here.
- godot-performance-optimization β Flyweight sharing, pooling RefCounted payloads, and when
.resbeats text.tresat scale.
Downstream / consumers
- godot-inventory-system β Item stacks, equipment, and bags consume
ItemData/ inventory Resource arrays defined here. - godot-procedural-generation β Generators that instantiate loot, quests, and configs via
Resource.new()at runtime. - godot-monte-carlo-balancer β
.tresstats and economy tables are the preferred extract source β build the data layer before regex farms.
Master
- godot-master β Library router and mirrored module entry for cross-skill discovery.