How to create a new ShaderMaterial (v4beta10)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By isolin

I want to create a new ShaderMaterial in C#. For now I’m trying out something very basic like constant blue. However, it fails. The same shader works fine when I create it over the editor, but I need the assignment to happen in code, of course once I get this toy example running I will extend the shader.

var mesh = new MeshInstance3D() {
    Mesh = new BoxMesh(),
    Position = new Vector3(x, -z, y)

mesh.MaterialOverlay = new ShaderMaterial {
  Shader = new Shader {
    Code = @"{
      shader_type spatial;
      void fragment() { ALBEDO = vec3(0., 0., 1.); }

The mesh stays grey. I am missing something? Even when I make the shader syntax wrong I get no compilation error, so I suspect some compilation of linking call is missing somewhere, but I didn’t find anything in the docs. So how to approach this?

:bust_in_silhouette: Reply From: isolin

So it turned out that the shader code was wrong. The very first character { is a mistake. It’s a pity that Godot does not report such errors.