Skip to content

Enable script class resource exports.

Will Nations requested to merge github/fork/willnationsdev/gdres into master

Closes godotengine/godot-proposals#18 for GDScript. To add support for custom resource exports in other languages, all you would have to do is add script class support to those languages (godotengine/godot-proposals#22) and program their export code to correctly set the class_name and hint_string values for the PropertyInfo object.

Credits:

Much of this work derives from @vixelz's efforts from #26162, so some credit is due there.

Changes:

I have fixed some of the concerns addressed by those who commented on that PR, namely...

  • regular export hints getting messed up in the process (fixed, screenshot demonstration below)
  • it operating from scanning an identifier rather than reducing a constant (it now reduces a constant and iterates through languages to check if any of them can find a script class name for the script).

Caveats:

As for using preloaded constants, I have decided to forego any implementation on purpose since...

  1. Preloaded constants only have a name within the scope of the actual script they reside in. When the editor views the name, there is no globally recognizable location in which it can pull the name and convert it into a script instance to test if the assigned resource instance is type-constrained properly.
  2. Non-integer constants are not a concept within the Object API so they cannot be language-agnostically accessed from editor code even if it did know the name of the constant. This point is pretty ironic too since most scripting languages implement their own support for read-only StringName->Variant maps to enable the use of constants anyway. Maybe if that feature became part of the Object API, we would be able to add better support for this as it would be "just another place to check" when examining where a valid inheritor comes from.

Screenshots:

Here are some images of the PR in action. It demonstrates...

  1. Various export hints combined with type hints all working together.
  2. Using a MyResource export hint and assigning to it a DerivedMyResource instance.
  3. The resource dropdown displays the list of types that correctly extend the custom resource script class.
  4. What it looks like when you preload a constant and attempt to export it (you get an error).
example_node_script example_export_derived_in_dropdown bad_script_class_export

Edit: Fixed a bug where the custom resource icons were not displaying in the Inspector. The screenshots are outdated in this respect, so keep in mind that class icons will appear in the resource dropdown menu.

Merge request reports