0 votes

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

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 [
            hint_string="A_resource" # or "res://a_resource.gd"

in plugin.gd

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():

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.

Godot version 3.4.2.stable
in Engine by (79 points)
edited by

1 Answer

0 votes

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

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:
            return effect
    return null

# Important. Without this you cannot edit the property
func _set(property, value):
    match property:
            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.

by (270 points)
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 Frequently asked questions and 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 [email protected] with your username.