Topic was automatically imported from the old Question2Answer platform.
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"
}
]
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.