Guide to the Godot game engine/Creating resources
Appearance
To make a new Resource, you need to make a new script (that is not attached to a node). Here is an example:
tool extends Resource export (int, INT, STRING) var property_type = 0 setget set_type var property func _get_property_list(): var out = [ { "name": "Property", "type": [TYPE_INT, TYPE_STRING][property_type] } ] return out func _get(what): if what == "Property": return property func _set(what, to): if what == "Property": what = to func set_type(value): property_type = value match value: 0: if !property is int: property = int(property) 1: if !property is String: property = String(property)
A simple example that shows a resource that can store either an int or a String.
The _get_property_list()
must return an Array of Dictionarys, each with the following values:
The following are optional:
- hint (int):
PROPERTY_HINT_*
constants. - hint_string (String)
- usage (int):
PROPERTY_USAGE_*
constants.
property_type
is too simple to need to be changed or defined with _get_property_list()
. Instead, export
is used, along with setget
to process when it is changed.
When property_type
is set, the type of property
is changed.
Real-world examples include storing keys or images. A resource just holds data for other scripts, it doesn't actually process it itself.
- Getting started [ ]
- Making it work
- Making it look good
- Advanced help
- Miscellaneous