- Home /
Reading mesh original colors?
I am doing some vertex coloring. I change the meshFilter.mesh.colors so that the changes are only temporary and different instances of the same mesh can be colored differently.
After coloring the mesh instance, I expect meshFilter.sharedMesh.colors to remain the original colors of the mesh, but they are not, sharedMesh.colors return the colors of the mesh instance..
Should i submit it as a bug, or is there another way of getting the original colors?
Answer by scarletshark · May 06, 2015 at 02:41 PM
Why don't you create a new script called MeshInfo, and apply it to your prefab. Inside the script, do the following:
using UnityEngine;
using System.Collections;
public class MeshInfo : MonoBehaviour {
// these fields will be publicly accessible, but can only be set by this class
public Mesh mesh{ get; private set; }
public Color[] originalColors{ get; private set; }
public Vertex[] vertices{ get; private set; }
void Awake() {
mesh = GetComponent<MeshFilter>().mesh;
vertices = mesh.vertices;
originalColors = mesh.colors;
}
}
Then in your other class you just say
getComponent<MeshInfo>().originalColors;
Thanks, but that is not really practical, as I change many meshes from one script. Is there no way of getting the mesh colors of the source mesh?
Why not? Can you post your code? I'm wondering if maybe I could have been more clear, because this should still work!