#Cant seem to change the colours of the vertices

1 messages · Page 1 of 1 (latest)

warm sand
#

im making a mesh for my map thats procedurally generated and im trying to colour all the top faces green. ive created a new list and i add the colour to that and then i set the list.ToArray() to the mesh colours like done on the Unity Documentation. Im not sure why it isnt working. Both lists are the same length and I use this code to add coloour

verts.Add(currentPos + new Vector3(0, 0, 1));
verts.Add(currentPos + new Vector3(1, 0, 0));
verts.Add(currentPos + new Vector3(1, 0, 1));

coloursVerts.Add(Color.green);
coloursVerts.Add(Color.green);
coloursVerts.Add(Color.green);
coloursVerts.Add(Color.green);```

```newChunk.GetComponent<MeshFilter>().mesh.colors = coloursVerts.ToArray();```
any help would be appreciated thanks
lusty spade
#

Make sure that your mesh is using a shader that actually displays vertex colors.

lusty spade
#

That's also something you could have googled.

warm sand
lusty spade
#

...you are literally setting the vertex colors of your mesh in code.
The mesh data and the settings of the renderer (including its assigned material and shader) is all the renderer cares about.

#

So you don't have to do anything beyond what you are already doing.

warm sand
#

but thank you, i didnt know it was as simple as that

lusty spade
#

In order to render an object, Unity takes the Mesh data supplied by the MeshFilter component and, the rendering properties given by the MeshRenderer, and draws that in the position, orientation and scale provided by the Transform.

The Mesh contains information about the basic structure of the rendered object - where are its points (vertices), which of those points are connected through faces, where do those faces point (normals), and how are textures placed on the faces (UVs).
The Material basically represents an instance of a Shader, with individual properties. It determines, how the object is rendered - determining stuff like reflectiveness, emission, transparency, etc.
The Renderer meanwhile adds some more physical properties - does the object cast shadows, does it receive shadows, etc.

An object's colors are usually determined by the material and shader, often by use of textures. That is also what Unity's default material does.
Because of that, if you want to render vertex colours, you will need a specialized shader.

warm sand
lusty spade
#

A similar idea to what?

warm sand
#

sorry i realised i was talking about uvmapping and worked it out