- Home /
Does anyone know how to change the Mesh in the SkinnedMeshRenderer?
So, I'm trying to change this component in C#. But don't fully understand how.
I tried this: playerGraphics.GetComponent().sharedMesh = blueDressMesh.sharedMesh;
But it gives a strange error.. (Array index (0) is out of bounds (size=0) unity)
Answer by dan_wipf · Jan 15, 2019 at 07:58 AM
well basically you need to set there a mesh.
accusing the SMR is this:
Mesh myMesh;
SkinnedMeshRenderer smr = transform.GetComponent<SkinnedMeshRenderer>();
smr.sharedMesh = myMesh;
Mesh myMesh can be everything, you can set it as a public Property, or you can search for a mesh in a GameObject, something like this:
public GameObject myGameObject;
myMesh = myGameObject.GetComponent<MeshFilter>().sharedMesh;
Have you tried it? I found out that what I did works, and is about the same as what you do. But just get an infinite error of "Array index (0) is out of bounds (size=0)" So I actually just want to stop this error : p because it's already doing what it should.
ok i've tested this, and not a single error about IndexOutOfRange.
using UnityEngine;
[ExecuteInEdit$$anonymous$$ode]
[RequireComponent(typeof(Skinned$$anonymous$$eshRenderer))]
public class S$$anonymous$$R_Test : $$anonymous$$onoBehaviour {
public $$anonymous$$esh my$$anonymous$$esh;
void Update () {
if(my$$anonymous$$esh != null){
transform.GetComponent<Skinned$$anonymous$$eshRenderer>().shared$$anonymous$$esh = my$$anonymous$$esh;
}
}
}