Managing a list of resources and their paths is hard
Asked Answered
P

5

0

Hi!

I can't find a way to manage some of my resources without having to hardcode string paths somewhere. And I would prefer to avoid that at all costs because I am still making frequent changes to the game folder structure.

I also don't really want to use a singleton for that as those resources don't spread across the whole game.

What i identified as somehow decent solutions :

  • When declared with class_name, the resource scripts seems to be accesible anywhere. It could store an enum with an associated array of paths

  • A tool script scene could have an exported resource folder property to keep track of the current resources of one type. But it should be instancied in every scene that need those resources

  • The possibility to fill with all .tres files an exported array in a ResourceList scene could be a trick but that would become overwhelming for thousand of resources (like it would be with a singleton paths manager)

  • Maybe a global dictionary (of resource types) of dictionaries (of single resource name and path) could be another solution ?

In other words, i'm lost

Prine answered 28/2 at 19:16 Comment(0)
G
0

Prine If you assign a resource to an exported property in the editor, the engine will track any renaming and moving of that resource file done from within the editor (in FileSystem tab). Every property in the project that refers to the resource in such a way will be automatically updated with the new path.

Glottology answered 28/2 at 20:30 Comment(0)
R
0

Depends what's your game, but I have an RTS in the making where I have exported arrays in a global_database script/node autoload.

@export var units : Array[r_unit]
@export var buildings : Array[r_building]

So when I want to access those ressources, I just call :
GlobalDatabase.units[0] will reference the first unit in the units array.

And if I want a building that can recuit units, I can just have an array inside that building that contains IDs that will reference the GlobalDatabase.units array

Rocker answered 29/2 at 15:13 Comment(0)
P
0

I spent the past night trying to write my own CustomResource@tool plugin and it ended far from success. I got into previously unknown to me territories like overriding _get_property_list() to get a dynamic dropdown list of all created CustomResourceType. When choosing one, that would append in the inspector the exporties properties of the CustomResourceType chosen. Then I forgot where I was heading and it was a whole mess.

SO,
someone on Discord pointed me towards plugin to get a global and safe list of all resources created :

Godot Resource Groups is a library for dynamically loading resources in Godot. In Godot you can only load resources if you know their paths in advance. This means you will need to hard-code all resource paths. This is not only error-prone it also prevents bulk-loading of resources unless you hard-code each and every resource path.

With this library you can define resource groups - a set of resources that belong together. You can then load these resources from your game code with a single line without having to hardcode the paths to the resources and doing any directory scanning.

Seems pretty straightforward and should suit my needs

Simple yet effective Quality of Life enhancement for Resource management in Godot.
Adds a new "Resources" tab with a tree view, where you can manage all of your resources in one place.

Even simpler, iterate through your filesystem and update a dock with a tree of your resources types and their "instances"

That and structs on 4.3 and I am good to go

Prine answered 29/2 at 19:48 Comment(0)
A
0

Prine Those look nice. derkork also creates really good godot tutorials https://www.youtube.com/@godotneers/featured

Astern answered 29/2 at 21:1 Comment(0)
P
0

Yeah I love the work he is doing. I am already using his State Charts extension which is a neat improvement of the state machine pattern. The documentation is complete and user-friendly AND he made an extensive video tut about it !

Prine answered 29/2 at 22:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.