Resources - Best Practice and Scalability

So I’ve never understood resources (for the following use case), and I’m hoping to get some insight that I’ve missed to help them click. I see them being used a lot in tutorials and public projects, but from my perspective they see to be inefficient and unscalable. I’m saying this from the viewpoint of projects that I’m interested in doing, I’m not saying they’re bad for all use cases.

Example:

  1. I create a game that will have hundreds or thousands of items.
  2. I create a table (dataset) of items in Excel with a dozen (or more) stats: cost, various effects, sprite or atlas location, etc.
  3. Export the table to csv, then convert to json. Read the json in Godot to dynamically generate the items.
  4. I can add or remove stats, as well as new items quickly and easily. I just have to make a few minor changes and re-export.

Using resources for this common type of case would be terrible. Having hundreds or thousands of files to modify individually in the editor is awful practice. I know you could write scripts to modify resource files, but that somewhat goes goes against the idea of resources, and is more cumbersome than using standard formats. If you have to modify resources dynamically by script, you’re IMO being stubborn rather than practical.

Once again, I’m not saying that resources are bad for all use cases, but I think they are for any case that involves a fair amount of data. Is there something I’m missing? Is this just a trap for beginners that is loved by people making tutorials? Did something go completely over my head?

No that seems right, if you have no use for methods on the items then a dictionary should suffice. Even so you could write a helper class that can do basic functions based on the type of item.

The thing is you will probably have some sort of visual representation of the item. There are lots of coding tricks to avoid having to write code for each item. This is typically done by encapsulating core features that are shared by a group of items, allowing you to reuse a single file of code for an infinite amount of unique items. This is the core of OOP and it’s feature of class Inheritance.

The one benefit in using resources is that they are reference counted, so they will delete themselves if no one is holding a reference anymore. An object class is not and should be handled with care to not leak memory. Dictionaries are also reference counted.

A half-joking solution:

https://godotengine.org/asset-library/asset/1469

For a more serious answer, you actually are using Resources, because (depending on the Godot version you use) JSON files are treated as Resources. It’s just that (1) you have an entire database as a single Resource (nothing wrong with that) and (2) the inspector is, indeed, not the ideal tool for editing data in this format, just like it won’t help you edit PNG images - another supported type of Resource.

Had to come back here because Godotneers recently released a video that discusses this very topic:

The part about editing several resources is at the very end, and it does use a spreadsheet plugin as I half-joked above (a better one though)! The rest of the video is an incredibly detailed step-by-step guide that showcases the power of Godot resources.