Langsung ke konten
Skillpedia
Pemrograman umum6.6k Β· #13827

godot-resources

Fungsinya

Skill ini menunjukkan cara menyimpan informasi game seperti item dan statistik dalam file resource Godot, bukan dalam kode. Skill ini ditujukan untuk orang yang ingin mengedit data game tanpa menulis ulang skrip.

Kapan dipakai

  • βœ“Saat Anda ingin menyimpan item, statistik, atau pengaturan musuh sebagai file data di Godot.
  • βœ“Saat Anda perlu membuat file resource .tres atau .res dalam proyek Godot.
  • βœ“Saat Anda ingin memuat data game sesuai kebutuhan atau mengubah resource bersama dengan aman saat berjalan.

Link skill

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/godot/godot-resources/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/godot/godot-resources/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œAtur game Godot saya agar saya dapat menambahkan senjata baru dengan mengedit sebuah file, bukan dengan menulis kode.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill menjelaskan cara membuat jenis resource kustom dengan field yang dapat diedit, menyimpannya sebagai file, mereferensikannya dari scene, dan memuatnya saat diperlukan.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Godot Resources (4.x)

Model game data as reusable, Inspector-editable Resource objects instead of hard-coded values, and load/save them as .tres/.res. Targets Godot 4.7.

When to use

  • Use when representing items, stats, enemy configs, dialogue lines, or level metadata as data; authoring .tres files in the Inspector; or loading/saving custom resources.

When not to use: nodes/scene structure β†’ godot-nodes-scenes; saving the player's runtime progress (engine-agnostic save format/slots) β†’ save-systems; the C# variant of this pattern β†’ godot-csharp.

Core workflow

  1. Subclass Resource with class_name and @export fields. It now appears in the "New Resource" dialog and as an @export type, editable in the Inspector.
  2. Create instances as .tres files in the FileSystem dock (text, diff-friendly) or .res (binary, smaller/faster). Edit their fields in the Inspector β€” no code needed.
  3. Reference resources from nodes via @export var data: ItemResource, or arrays @export var loot: Array[ItemResource].
  4. Load at runtime with preload (constant path) or load/ResourceLoader.load (variable path). Use threaded loading for large assets.
  5. Duplicate before mutating a shared resource at runtime, or every node using it changes too (resources are shared references).
  6. Save generated/edited resources with ResourceSaver.save.

Patterns

1. A custom data resource

# item.gd
extends Resource
class_name ItemResource

@export var id: StringName = &""
@export var display_name: String = "Item"
@export_multiline var description: String = ""
@export var icon: Texture2D
@export var max_stack: int = 99
@export var value: int = 0

Create sword.tres from this class in the FileSystem dock and fill it in the Inspector.

2. Consume resources from a node

extends Node
@export var starting_items: Array[ItemResource] = []   # drag .tres files in the Inspector

func _ready() -> void:
    for item in starting_items:
        print("Have: %s (x%d max)" % [item.display_name, item.max_stack])

3. Duplicate before mutating shared data

func give_unique_copy(template: ItemResource) -> ItemResource:
    # true = deep: copies nested arrays/dictionaries and *embedded* sub-resources, but
    # sub-resources saved in their own .tres stay shared. Use
    # template.duplicate_deep(Resource.DEEP_DUPLICATE_ALL) to copy those as well.
    var copy: ItemResource = template.duplicate(true)
    copy.value += 5                # mutating the copy won't touch the template .tres
    return copy

4. Save and load a resource at runtime

func save_config(cfg: Resource) -> void:
    ResourceSaver.save(cfg, "user://config.tres")   # user:// = writable app data dir

func load_config() -> Resource:
    if ResourceLoader.exists("user://config.tres"):
        return ResourceLoader.load("user://config.tres")
    return null

Pitfalls

  • Resources are shared by reference. A single .tres assigned to many nodes is the same object β€” mutating it changes all of them (and re-saving the file). Call duplicate(true) for per-instance state.
  • A deep copy still changes the original's sub-resource β†’ duplicate(true) only copies sub-resources embedded in the file; one saved as its own .tres (e.g. a shared stats.tres inside goblin.tres) is still the same object. Use duplicate_deep(Resource.DEEP_DUPLICATE_ALL) when those must be copied too.
  • class_name required to instance from the editor. Without it the class won't appear in the "New Resource" dialog or as an @export type.
  • res:// is read-only in exported games. Write runtime data to user://, never res://. ResourceSaver.save to res:// only works in the editor.
  • Storing nodes in a Resource doesn't serialize them. Resources hold data, not live scene nodes. Reference scenes via PackedScene, not node instances.
  • Cyclic resource references (A holds B holds A) can fail to save/load cleanly β€” keep data graphs acyclic or use IDs/lookups.
  • preload vs load. preload needs a constant path and loads with the script; load accepts a variable path at runtime. Use ResourceLoader.exists() before load to avoid errors on missing files.
  • Don't put secrets in .tres β€” they ship in plain text inside the export.

References

  • For threaded/background loading (load_threaded_request), `
Pertanyaan umum

Apa itu resource Godot?

Resource adalah objek data yang dapat disimpan ke file dan dibagikan antar scene.

Mengapa menduplikasi resource sebelum mengubahnya?

Resource adalah referensi bersama, sehingga mengubah satu salinan bersama akan mengubahnya di semua tempat yang memakainya.

Apakah ini untuk menyimpan kemajuan pemain?

Tidak juga. Menyimpan kemajuan pemain dicakup oleh skill penyimpanan yang terpisah.

Detail

Deskripsi asli dari pembuat

Design data-driven Godot 4.7 games with custom Resource classes: define typed data with class_name + @export, save/load .tres/.res files, instance and duplicate resources, and load on demand with ResourceLoader (incl. threaded loading). Use when modeling items/stats/configs as data in a Godot project, creating .tres resources, or working with custom Resource subclasses and ResourceLoader/ResourceSaver.

repo: gamedev-skills/awesome-gamedev-agent-skills

Popularitas

Bintang GitHub
6.6k
Peringkat
#13827
Lisensi
Apache-2.0
Diperbarui
28/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa