Enum not showing in custom visual shader node

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);"

Hey maybe remove the first part of the message the AI gave you :slight_smile:

4 Likes

A few things:

  1. Could you ask the AI to format the code so that it’s formatted as GDScript instead of generic code?
  2. Could you ask the AI why it’s using _get_property_list() when the example in the docs does not do that?
  3. 4.4 (Dev/Beta) is not a valid Godot version number. Could you ask your AI to tell you how to get the actual version number of your version of Godot?
  4. Could you ask your AI why it wrote a bunch of useless gibberish before getting to the point of the problem?
  5. Have you tried feeding the question it created back into it? Just because it formatted the question doesn’t mean it actually considered the question.
  6. That’s not how VisualShaderNodes work. The LLM is lying to you. Create parameters to feed in and use those to calculate whatever it is you want to calculate.
4 Likes

you are right. i was frustrated so much that i couldn’t even write my question.