- Home /
Question by
fixedgerald · Dec 23, 2017 at 10:00 PM ·
meshmeshrendererskinnedmeshrenderer
Modifying SkinnedMeshRenderer.sharedMesh.uv Doesnt Reset after Stopping game.
I'm modifying SkinnedMeshRenderer.sharedMesh.uv of a model to change the vertices trying to animate them. However when I stop the game the changes stay on the model, and starting the game again the changes are still there. How do I prevent this from happening?
Screenshots: https://imgur.com/a/Jrb6K Running the app a second time will offset the texture again.
Code:
SkinnedMeshRenderer meshRend = GetComponent<SkinnedMeshRenderer>();
mesh = meshRend.sharedMesh;
uvs = mesh.uv;
for(int i = 0; i < uvs.Length; i++)
{
uvs[i] = new Vector2(uvs[i].x - 0.01f, uvs[i].y - 0.01f);
}
mesh.uv = uvs;
Comment
Best Answer
Answer by fixedgerald · Dec 23, 2017 at 10:28 PM
So I think I found a workaround, by copying the mesh, modifying the copy, then assigning that to the SkinnedMeshRenderer.
Code:
SkinnedMeshRenderer meshRend = GetComponent<SkinnedMeshRenderer>();
Mesh mesh = meshRend.sharedMesh;
var mesh2 = Instantiate(mesh);
Vector2[] uvs = mesh2.uv;
for(int i = 0; i < uvs.Length; i++)
{
uvs[i] = new Vector2(uvs[i].x - 0.01f, uvs[i].y - 0.01f);
}
mesh2.uv = uvs;
meshRend.sharedMesh = mesh2;