godot: Custom-made resource types cannot be used in export statement

Operating system or device - Godot version: Windows 10 - Godot 2.1 Stable

Issue description (what happened, and what was expected): Created a custom resource type as a plugin and attempted to export(CustomResource), which raises error(17,7): Export hint not a type or resource.

Steps to reproduce: Create a plugin which defines a custom resource type. add_custom_type like the plugins tutorial shows (Specifically, add_custom_type("Name", "Resource", preload("plugin_source.gd"), preload("icon.png"))). The new type will appear in the “create resource” menu, but attempting to export(CustomResourceName) will raise the error.

Link to minimal example project: Custom Resource (2.1s).zip

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 42
  • Comments: 22 (5 by maintainers)

Most upvoted comments

Games which are data-heavy (such as RPGs) would benefit immensely from better support for user-defined resources; there is a great deal of convenience in being able to see and modify game data in-engine via the FileSystem and Inspector, and being able to create, save and load this data without having to go through a parser. Thanks to the new class_name functionality, it is possible to create a user-defined resource easily from the ‘Create New Resource’ menu, but exporting these resources is unfortunately still not supported as of f50dd682f6a0f9506daaf16fed06f4bc9efa6599

Let’s say I want an exported CustomResource property in one of my script. Right now, I can legitimately only do that with:

export(Resource) var custom

And then select CustomResource in the very long list of resources. But if I write this instead:

export(Curve) var custom

When I try to set it in the editor, I obtain: image Which is incorrect! I should only have Curve in the list! Buuut… it lets me easily select CustomResource, which is what I want.

This is 100% a hack, and not a viable long term solution! It might even stop working once this issue is fixed. But in the meanwhile, it allows at least to use custom resources and move on. We can even write export(Curve) in the script just to create the resource in the editor, then change it to export(Resource) once it’s done (the created resource will still be in the scene, everything works, and the code remains consistent). Not a great solution, but that might do for some projects, until we have a fix.

@Jeto143 Yes, it’s planned for 4.0.

Anyway, I’ll close this in favor of https://github.com/godotengine/godot-proposals/issues/18, as feature proposals are now tracked in the Godot proposals repository.

Could this make it to 4.0? This has been asked in 2016, and the amount of thumbs up speaks for itself.

This would be really nice to have, and I doubt it’s a massive change to make.

@EmeraldSlash I think you might be commenting on the wrong issue?

Currently, you cannot export variables of type Node, as it is not a primitive or resource type. Try NodePath or String.

Sorry for the bump, I just found this issue after commenting about it here: https://github.com/godotengine/godot/issues/3597#issuecomment-425670625

@somnivore Thanks to the new class_name functionality, it is possible to create a user-defined resource easily from the ‘Create New Resource’ menu, but exporting these resources is unfortunately still not supported as of f50dd68

Yeah, supporting custom resource types in exported variables will greatly improve the custom resource workflow. It would be nice to see this implemented yet for 3.1

For the sake of posterity I checked to ensure that the problem wasn’t already solved in v3.0.2.stable.official - it’s not. Attempting to export(CustomResource) raises an error “Expected a constant expression”, and trying to export(Resource) does not put the custom resource in the drop-down menu. However, the custom resource does appear in the “create resource” menu, can be saved, and can be manually slotted in from a saved tres.

I’ll be building a version of the editor from the commit of the linked PR soon and replicating my efforts there to see what happens.