How can i get current state(position) of vertices of animated mesh(SkinnedMeshRenderer)?

Unity doesn’t give you access to those. The only thing you can do is to replicate the same code in scripts and calculate those vertex-positions. It’s ok for simple things, but doing it every frame would be too expensive.

Edit:
Look at this link: http://forum.unity3d.com/threads/14378-Raycast-without-colliders
It has a sample how to update MeshCollider from SkinnedMeshRenderer manually in scripts. It does almost exactly what you need.

If i understood correct i can't get vertex positions in any way?

3 Answers

3

I’m not sure if this has a solution in Unity 3. In unity 4 the following works for me:

SkinnedMeshRenderer skin = model.GetComponent<SkinnedMeshRenderer>();
Mesh baked = new Mesh();
skin.BakeMesh(baked);

Baked will contain all the current vertex positions of the skinned and animated mesh. It seems to work slowly though, as far as I can tell, so be careful how often you call this.

Well it depends on what vertex you are looking for. Do you want them all? If so you could make a copy of them by using your mesh component like this.

Vector3 actualVertices;
MeshFilter meshFilter = (MeshFilter) gameObject.GetComponent("MeshFilter");
actualVertices = meshFilter.mesh.vertices;

The question is about SkinnedMeshRenderer, not about rigid meshes (i.e. MeshFilter).

Sorry to necro but this worked for me so here it is:

Transform tOwner;
SkinnedMeshRenderer skinnedMeshRenderer;
List<Vector3> meshVertices = new List<Vector3>();
public void GetVertices()
{
    Mesh mesh = new Mesh();
    skinnedMeshRenderer.BakeMesh(mesh, true);
    mesh.GetVertices(meshVertices);
    tOwner = skinnedMeshRenderer.transform;
}
public Vector3 GetPositionFromVertex(int i)
{
    Vector3 worldPosVertex = tOwner.localToWorldMatrix.MultiplyPoint3x4(meshVertices*);*

return worldPosVertex;
}