Godot Version
4.4
Question
I am trying to create a VisualShaderNodeCustom in GDScript that exposes a Gradient resource and an Enum dropdown in the Inspector.
The properties in the Inspector consistently display as “Default” with no other enum values. I have tried clearing the cache, restarting the editor, and renaming the class, but the engine seems to fail to bind the PROPERTY_HINT_ENUM metadata to the UI.
How do you correctly register an Enum dropdown for a custom Visual Shader node so the Inspector actually renders the hint_string options?
GDScript
@tool
extends VisualShaderNodeCustom
class_name BlenderRamp
var gradient: Gradient = Gradient.new()
var interpolation: int = 1
func _get_name() -> String:
return "BlenderRamp"
func _get_category() -> String:
return "Custom"
func _get_return_icon_type() -> int:
return PORT_TYPE_VECTOR_3D
# This indexed system is used in VisualShaderNodeCustom
# but consistently results in "Default" labels in the Inspector.
func _get_property_count() -> int:
return 2
func _get_property_name(index: int) -> String:
match index:
0: return "gradient"
1: return "interpolation"
return ""
func _get_property_type(index: int) -> int:
match index:
0: return TYPE_OBJECT
1: return TYPE_INT
return 0
func _get_property_hint(index: int) -> int:
match index:
0: return PROPERTY_HINT_RESOURCE_TYPE
1: return PROPERTY_HINT_ENUM
return 0
func _get_property_hint_string(index: int) -> String:
match index:
0: return "Gradient"
1: return "Constant,Linear,Ease"
return ""
func _get_property_default_value(index: int) -> Variant:
match index:
0: return Gradient.new()
1: return 1
return null
func _set(prop: StringName, val: Variant) -> bool:
if prop == &"gradient":
gradient = val
emit_changed()
return true
if prop == &"interpolation":
interpolation = val
emit_changed()
return true
return false
func _get(prop: StringName) -> Variant:
if prop == &"gradient": return gradient
if prop == &"interpolation": return interpolation
return null
func _get_input_port_count() -> int: return 1
func _get_input_port_name(p): return "fac"
func _get_input_port_type(p): return PORT_TYPE_SCALAR
func _get_output_port_count() -> int: return 1
func _get_output_port_name(p): return "color"
func _get_output_port_type(p): return PORT_TYPE_VECTOR_3D
func _get_code(input_vars, output_vars, mode, type):
return output_vars[0] + " = vec3(0.0);"