@export GDScript

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By OTGOD

In the docs, I found I can use this code:

@export var resource: Resource

to manually set a resource in the IDE. This way I get a dropdown full of objects I can choose from. I can even write a thing like this one:

@export var resource: GDScript

but, how can I use it? I created a new GDScript file (just a simple function) and dragged it in the export field, but I can’t use it from the class that features the @export.

So, how is this eventually supposed to work (if it works)?

[EDIT] I found a way to make it work, but still I couldn’t imagine a use case for this. Anyway, for anybody reading, this way it works:


I can think of a use case. I am writing a plugin for designing cutscene graphs, and I might want to have a node type where arbitrary GDScript could be specified. I would need something like this in order to run it. Not sure if I actually will do that though!

HyperlinkYourHeart | 2023-06-28 14:10

Ok, but what’s a “cutscene graph”? :slight_smile:

OTGOD | 2023-06-29 06:42

It’s a graph that describes a cutscene or dialogue. I guess it’s more about dialogue than cutscenes, but for some reason I started calling everything it does “cutscenes”

Anyway I’m glad to know this feature exists even if it would be pretty rare to need it. I’d say it would mostly be useful for editor plugins and custom node types.

HyperlinkYourHeart | 2023-06-29 09:06

You can avoid the .new if instead you create an empty Resource, save it as my_resource.tres, then attach a script to it. Then you can drag it to your @export var resource : Resource and you can directly use functions of it. With the added bonus that since the resource is a .tres, the script attached to it can also export variables which can be modified and saved into the my_resource.tres.

Zylann | 2023-07-06 15:07