Here's a rudimentary custom resource:

extends Resource

export(Resource) var scr

I can drag a pre-made .gd script into this exported property in Inspector, and it works as intended. I can click on the exported property field and embed a resource (like "New ShaderMaterial"), and it would also work as intended, and I would be able to edit that sub-resource normally. However, if I click on the exported property and select "New GDScript", there doesn't seem to be a way to open the new gdscript for editing. Is it possible to embed a gdscript sub-resource the same way you can embed a different sub-resource?

  • \$\begingroup\$ Could you tell me of an example use-case for this? I am having a hard time understanding what can be achieved with this. \$\endgroup\$
    – ZektorH
    Jan 28, 2020 at 16:20
  • 1
    \$\begingroup\$ Let the custom resource represent a consumable item. It contains normal item fields, like price, weight, inventory icon, etc, but also a script of what would happen should you consume it. \$\endgroup\$ Jan 29, 2020 at 15:24

1 Answer 1


As far as I can tell, Godot does not provide any GUI for this, but it is possible. When you add a GDScript to your resource, you will see that it is given a path within the resource file:

enter image description here

If you crack open new_resource.tres in a text editor, you'll see the following:

[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://MyResource.gd" type="Script" id=1]

[sub_resource type="GDScript" id=1]

script = ExtResource( 1 )
scr = SubResource( 1 )

You can write your script under the GDScript sub_resource like so:

[sub_resource type="GDScript" id=1]
script/source = "extends Spatial

func _ready():
    pass # Replace with function body.

This feels rather hacky, so you might consider submitting a proposal if this workflow is important to you.

  • \$\begingroup\$ Granted, I haven't used Godot in a while, but isn't there already an option to embed the GDScript into the resource from the dialog that pops up when you attach a new script file? I'm almost certain I've done this before, without requiring workarounds. \$\endgroup\$
    – flesk
    Jan 29, 2020 at 6:18
  • \$\begingroup\$ @flesk I believe the "attach script" dialog only appears when you attach a script to a Node, not when you assign one to an exported field. I'd be delighted to be proven wrong though :) \$\endgroup\$
    – rcorre
    Jan 29, 2020 at 11:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .