• 3D
  • [SOLVED] Setting surface tool vertex color doesn't work

Hi there,

I am trying to understand how I can set a vertex color when creating a mesh with the SurfaceTool class. I am following this tutorial : https://randommomentania.com/2018/11/godot-surface-tool-tutorial/

However, I am on Godot v3.1.2.stable.official and the first example with the triangle doesn't work : the color is white...

extends MeshInstance

func _ready():
	var surface_tool = SurfaceTool.new();
	
	surface_tool.begin(Mesh.PRIMITIVE_TRIANGLES);
	
	surface_tool.add_normal(Vector3(0, 0, -1));
	surface_tool.add_color(Color(1, 0, 0, 1));
	surface_tool.add_vertex(Vector3(-1, 0, 0));
	
	surface_tool.add_normal(Vector3(0, 0, -1));
	surface_tool.add_color(Color(0, 1, 0, 1));
	surface_tool.add_vertex(Vector3(1, 0, 0));
	
	surface_tool.add_normal(Vector3(0, 0, -1));
	surface_tool.add_color(Color(0, 0, 1, 1));
	surface_tool.add_vertex(Vector3(0, 2, 0));
	
	surface_tool.add_index(0);
	surface_tool.add_index(1);
	surface_tool.add_index(2);
	
	mesh = surface_tool.commit();

What I am doing wrong? (a zip file of a simple project is provided)

Oh sorry I just found that you need to create a new Spatial material in your MeshInstance options (GeometryInstance > Material Override > New Spatial Material" and then change the Vertex Color > Use as Albedo option to On !

Cool. Thanks for following up with the solution.