Hi ! I created a simple shader to turn my cube into a transparent cube, and would like to apply / remove the shader when pressing a key.
I tried some cide I found online and in the godot docs but it doesn’t work nor does it return an error :
func change_shader():
print(“blueprint active !”)
var model = self.get_node(“Area3D/MeshInstance3D”)
model.set_surface_override_material(0,BLUEPRINT_SHADER)
Hello!
Just to be sure, did you try to do it manually in the editor yet?
Does it turn transparent if you do it like that?
Then upon running it and then using the change_shader() method, can you go into the Remote tab located in the top left side of the editor? Is the shader correctly applied there? Do you even get the print(“blueprint active !”) output?
Lastly, could I ask you to rightclick on the MeshInstance3D and then access as unique name? Afterwards drag the node into the editor on line36 instead of model, basically turning it into %MeshInstance3D.set_surface(...)
Super lastly, are you super sure set_surface_override_material() needs a shader code? I believe it needs a material.
Therefore my proposal:
var override_material = ShaderMaterial.new()
override_material.shader = BLUEPRINT_SHADER
%MeshInstance3D.set_surface_override_material(0, override_material)
Sooo I kind of gave up the shader idea and used a simple material and tried your method and couldn’t get it to work, and when I tried to access as a unique name I got an error (can’t remember what as it was a few days ago) which seemed to be link to an error in the type of ressource.
When I saved my texture, I must have messed up somewhere as when I tried to delete the .tres object and save it again, your code was working… oddly enough, both ressource ended with .tres but one was the frong type