godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Support persistent metadata on imported resources #9555

Open and-rad opened 5 months ago

and-rad commented 5 months ago

Describe the project you are working on

A game that requires diligent tracking of third-party licenses and CC-type attribution on individual assets.

Describe the problem or limitation you are having in your project

In trying to find an efficient way to track and store asset attributions, I come up against different limitations in the engine that makes the whole thing more complicated than it would ideally be. My requirements are:

  1. Store asset license attribution on the imported asset directly. The goal is for the attribution info to be found easily and to disappear automatically as soon as the asset gets removed from the project. We want to minimize bookkeeping.
  2. Persist the attribution information across reimports and be able to check it into version control.
  3. Provide a user interface for entering attribution information in order to reduce the range of possible mistakes, be able to use templates for licenses that are used often, and to be able to validate input.
  4. Collect license attribution automatically via editor menu options or during CI/CD pipelines.

Of the above, only numbers 1 and 2 cause significant problems, 4 is no issue at all and 3 is solved with a custom inspector plugin. I just can't find a way to store custom information per resource that satisfies these two requirements. Imported scenes do not seem to suffer from the same limitations, but I need to explore my options there further.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I can think of several ways to make this possible, but the easiest seems to be making sure that metadata on imported resources can be edited with GDScript and persists after reimporting a resource. The field exists already and is used by importers:

[remap]

importer="texture"
type="CompressedTexture2D"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}

For reference, Unreal Engine provides a field called Asset User Data on all imported assets, which is an array of an inheritable base class that you can use to pass arbitrary user data that is stored with the asset:

grafik grafik

This is essentially what I'm trying to build.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  1. Make sure resource importers preserve metadata that is not related to their own functionality.
  2. So far as it is needed, extend Object::set_meta to be able to store data in an imported resource's metadata field, and Object::get_meta to read it. I haven't gotten around to testing whether this is already the case, so this might already work.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not to my knowledge, at least when it comes to save additional data on any kind of imported resource. The overall goal I want to achieve (the attribution system) can be implemented in lots of ways that don't need this particular feature.

Is there a reason why this should be core and not an add-on in the asset library?

The engine doesn't expose the necessary classes and methods to implement this feature on the user side.

and-rad commented 5 months ago

Another way to get this done, but which I assumed might pose too much of a hurdle (but maybe not?), is to provide the same functionality that Unreal Engine does as described above. The base resource importer class would need a new field that is subsequently available for all imported resources. This field could take any resource as its value and the resource is serialized along with all the other import data.

Might be worth thinking about.