How to advance export plugin resource

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

I have created a plugin and there are some resources I’m trying to export which will be putting in a group

what I have tried (example):
in a_resource.gd

tool
extends Resource

const A_resource = preload("res://a_resource.gd") 
# This is used for other things in my script

func _get_property_list() -> Array:
    return [
        {
            name="Resource",
            type=TYPE_OBJECT,
            hint=PROPERTY_HINT_RESOURCE_TYPE,
            hint_string="A_resource" # or "res://a_resource.gd"
        }
    ]

in plugin.gd

tool
extends EditorPlugin

const A_resource = preload("res://a_resource.gd") 

func _enter_tree():
    var none_texture = StreamTexture.new()
    add_custom_type('A_resource', 'Resource', A_resource, none_texture)

func _exit_tree():
    remove_custom_type('A_resource')

It seems to be working, but actually, it’s outputting an error and the resource will be showing up no matter what resource you are exporting.

:bust_in_silhouette: Reply From: Juxxec

I have been trying to achieve something like you are. Here is how I did it:

My custom resource is called Effect and it is the following script:

class_name Effect
extends Resource
tool

export(int, "DamageOverTime", "Heal", "Poison") var type = 0

Then in another script where I want only resources of that type to be assigned:

class_name EffectVisualizer
extends Node
tool # Important. Without this the _get_property_list method does not get called

var effect : Effect = null

func _get_property_list():
	return [
		{
			"name": "effect",
			"type": TYPE_OBJECT, # This is important.
			"hint": PROPERTY_HINT_RESOURCE_TYPE, # This is important. Hint that this is a resource
			"hint_string": "Effect", # This is important. This is the name of the Resource Class
			"usage": PROPERTY_USAGE_DEFAULT,
		},
	]


# Important. Without this you cannot edit the property
func _get(property):
	match property:
		"effect":
			return effect
	return null


# Important. Without this you cannot edit the property
func _set(property, value):
	match property:
		"effect":
			effect = value
			return true
	return false

I hope ths helps. Sadly I could not get this to work when you want to have an Array of your custom resources, i.e.:

export(Array, Effect) var effects = []

P.S. you can still use normal export statements in the script. They will just get combined with whatever you add to your _get_property_list method.