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.
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())
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.
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
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
- renames_map_3_to_4.cpp line 1646, VisualShaderNodeColorUniform to VisualShaderNodeColorParameter
- renames_map_3_to_4.cpp lines 1645 to 1653, the other uniform nodes
- renames_map_3_to_4.cpp lines 375 and 558, get_shader_param and set_shader_param
- gdscript_analyzer.cpp line 4687, the error with the rename hint
- VisualShaderNodeColorParameter class reference
- VisualShaderNodeParameter class reference, parameter_name
- VisualShaderNodeUniform at 3.6-stable, uniform_name
Run on Godot 4.7.2, .