Godot Version
v4.5.dev.custom_build [bc651a3de]
(Built from my bug-fixed code)
Question
I am making a plugin now, and I have defined some data class extending Resource
. Here are one example of those class (I skipped the _init and other unnecessary methods):
class_name GraphNodeSlotInfo
extends Resource
## Class for storing the single GraphNode slot info
##
##
# End of class document.
enum SlotLocation
{
left,
right
}
## Index of the slot. Different for left/right side.
@export var index: int
## The location of the slot on the node.
@export var location: SlotLocation
const default_connection_category = 0
## `type_left`/`type_right` for the slot. By default, set to 0 in this project.
@export var connection_category: int = default_connection_category
const default_colour = Color(0.7, 0.7, 0.7, 1.0)
## Colour of the slot.
@export var colour: Color = default_colour
const default_icon_path = ""
## Icon of the slot.
@export var icon: Texture2D = null
## EditorIcon path of the slot's icon.
@export_dir var icon_path: String = default_icon_path
When I use ResourceSaver to save this, I found that some values with default are also saved:
colour = Color(0.7, 0.7, 0.7, 1)
icon_path = ""
How can I tell the ResourceSaver do not save the value that remains default (just like the behaviour of tscn files). I have tried _property_can_revert
but that does not seems to work.
func _property_can_revert(property: StringName) -> bool:
return property in self.list__revertable_properties
func _property_get_revert(property: StringName) -> Variant:
match property:
"connection_category": return self.default_connection_category
"colour": return self.default_colour
"icon_path": return self.default_icon_path
_: return null