+1 vote

Hi all-
I've created a custom resource plugin so I can keep a palette of colors that can be modified in one location and effect everywhere relevant. But when I try to export it with the type hint, BlockColors, it returns an error: error(17,7): Export hint not a type or resource.

Here are my files:

res://addons/block_colors/plugin.cfg

[plugin]

name="BlockColors"
description="A custom resource which holds a color for each Tetromino type"
author="Brandon Hustus"
version="1.0"
script="block_colors_plugin.gd"

res://addons/block_colors/block_colors_plugin.gd

tool
extends EditorPlugin

func _enter_tree():
    add_custom_type(\
    "BlockColors",\
    "Resource",\
    preload("block_colors.gd"),\
    preload("res://Blocks/Tetris Block.png")\
    )

func _exit_tree():
    remove_custom_type("BlockColors")

res://addons/block_colors/block_colors.gd

extends Resource

export(Color) var I_block_color
# More to be added later

When I try to export(BlockColors) in another script, it returns the error listed above. I have enabled the plugin and am able to create a resource of the BlockColors type. Have I done anything wrong, or is it just not possible to export a plugin resource type?

in Engine by (45 points)

1 Answer

+1 vote
Best answer

I'm not all that familiar with the source code, but if it doesn't add user defined types to the built-in types for the parser, then export is going to adhere to only built-in types.

I was curious as well, but this is as far I could find:

https://github.com/godotengine/godot/blob/c05ff0577fd9cc39a6968e65743f7d7da711bfe2/modules/gdscript/gd_parser.cpp#L2519

by (5,242 points)
selected by

Really? I'm not sure if that's a technical necessity in the code but it seems awfully short-sighted that they would let you make a resource without being able to use it in scripting. I'll wait around for a bit but if I don't find anything else I guess you have it!

I hear you on that.

Though it's a budding engine, there are many things in the works or overlooked. I recall reading some threads of requests wanting to include arrays as part of export, and some interest in having export provide categorization. I get the impression that in it's current state it's as hard coded as it appears for the time being.

Incidentally, I managed to make it work just by export(Resource) and using duck typing, but I still wish that I could expect the specific type.

Nice work.

Yeah, I imagine it's less than ideal.

It's unfortunate that GDScripts can't extend from Color.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.