Getting shader parameter value in gdscript returns nil?

Godot Version



Hello, I’m trying to set a material and shader parameter to a simple MeshInstance3D and then get the value of some things of said shader parameter in gdscript, but everything I tried still doesn’t work. It keep saying that the shader parameter is nil, even though everything else has a value. I hope the screenshot will help you understand. “heightmap” is always nil and terrain_mesh is a simple

Any help possible please ?

I would try two things…

Since these are static files use preload this may help raise any errors that you won’t see until runtime.

Other thing is there is the ResourceLoader singleton that may be required to establish the resources.

You are not setting the parameter correctly, it just needs the name of the parameter not the full path. terrain_material.set_shader_parameter("heightmap", texture) in this case.

Hello, I’m afraid it doesn’t change anything. Result still nil/null !
And I’m pretty sure the full path works too as I tried something else some days ago that had the full path and it still worked.

Pennyloafer’s answer didn’t change anything either, same problem.

(By the way I think the problem may lie not in the get_shader but instead in the set_shader as some very similar code I made worked when only getting the value of heightmap when the shader was applied manually in editor. But when setting the value in gdscript this problem arise)

That’s because you are setting an empty Texture2D which it’s treated as removing the parameter godot/scene/resources/material.cpp at 29b3d9e9e538f0aa8effc8ad8bf19a2915292a89 · godotengine/godot · GitHub. Use a working texture and it will work.

	mat.set_shader_parameter('tex', load("res://icon.svg"))
	var t =  mat.get('shader_parameter/tex')

That works fine.