Godot 3 to 4 rename

VisualShaderNodeColorUniform in Godot 4: it is VisualShaderNodeColorParameter now

VisualShaderNodeColorUniform is VisualShaderNodeColorParameter in Godot 4: visual shader uniforms are called parameters now, and the node's uniform_name is parameter_name. It still becomes a uniform vec4 in the generated shader code, but only once it is connected to another node.

What Godot prints

A Godot 3 script that builds a color uniform for a visual shader in code.

repro.gd
extends Node

func _ready():
	var shader = VisualShader.new()
	var tint = VisualShaderNodeColorUniform.new()
	tint.uniform_name = "tint"
	shader.add_node(VisualShader.TYPE_FRAGMENT, tint, Vector2(0, 0), 2)
	print(shader.get_code())
Output, Godot 4.7.2
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

SCRIPT ERROR: Parse Error: Identifier "VisualShaderNodeColorUniform" not declared in the current scope. Did you mean to use "VisualShaderNodeColorParameter"?
   at: GDScript::reload (res://answers/visualshadernodecoloruniform-in-godot-4/repro.gd:5)
ERROR: Failed to load script "res://answers/visualshadernodecoloruniform-in-godot-4/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)

The fix

The same node as VisualShaderNodeColorParameter, named with parameter_name, then connected to the first port of the fragment output. The fix prints the uniform lines of the generated shader code before and after connecting.

fix.gd
extends Node

func _ready() -> void:
	var shader := VisualShader.new()
	var tint := VisualShaderNodeColorParameter.new()
	tint.parameter_name = "tint"
	shader.add_node(VisualShader.TYPE_FRAGMENT, tint, Vector2(0, 0), 2)
	print("before connecting: ", uniforms(shader))
	shader.connect_nodes(VisualShader.TYPE_FRAGMENT, 2, 0, 0, 0)
	print("after connecting: ", uniforms(shader))

func uniforms(shader: VisualShader) -> Array[String]:
	var found: Array[String] = []
	for line in shader.get_code().split("\n"):
		if line.begins_with("uniform"):
			found.append(line)
	return found
Output, Godot 4.7.2
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

before connecting: []
after connecting: ["uniform vec4 tint : source_color;"]

Why it happens

GDScript's analyzer resolves every identifier when the script loads. VisualShaderNodeColorUniform is not a class in Godot 4.7.2, so the script fails to parse and Godot does not load it. The editor build adds the new name from Godot's 3 to 4 rename table: Did you mean to use "VisualShaderNodeColorParameter"?

Every uniform node of a Godot 3 visual shader is renamed the same way in that table: VisualShaderNodeUniform to VisualShaderNodeParameter, ScalarUniform to FloatParameter, BooleanUniform to BooleanParameter, TextureUniform to Texture2DParameter, CubemapUniform to CubemapParameter and TransformUniform to TransformParameter.

Godot 3's uniform_name property is parameter_name on VisualShaderNodeParameter: the name the parameter has among the ShaderMaterial's properties. From GDScript, ShaderMaterial's set_shader_param and get_shader_param are set_shader_parameter and get_shader_parameter.

The class reference says the node is translated to uniform vec4 in the shader language; the run shows the line Godot generated, uniform vec4 tint : source_color;. Its first line shows that a parameter added to the graph but connected to nothing is not in the generated code.

Sources

Run on Godot 4.7.2, .

Related