trying to create a mesh through script. I hacked the procedural skinned mesh script to what seems to make sense. no mesh appears but the mesh renderer and shader appears normally when the script is run.
I know the issue has to do with this being a skinned object that is now without bones.
You’re right in that I think that this is partially related to using the SkinnedMeshRenderer when you’re not using bones. But I think that the bigger issue is that you never use the MeshFilter component which is required (and that you reference in your own comments yet don’t use). Here is a simple code snippet that works on my end:
function Start () {
var myFilter : MeshFilter = gameObject.AddComponent(MeshFilter);
var myRenderer : MeshRenderer = gameObject.AddComponent(MeshRenderer);
// Build basic mesh
var tMesh : Mesh = new Mesh ();
tMesh.vertices = [Vector3(-100, 0, 0), Vector3(100, 0, 0), Vector3(-100, 500, 0),Vector3(100, 500, 0)];
tMesh.uv = [Vector2(0, 0), Vector2(1, 0), Vector2(0, 1), Vector2(1, 1)];
tMesh.triangles = [0, 1, 2, 1, 3, 2];
tMesh.RecalculateNormals();
// Assign mesh to mesh filter renderer
myFilter.mesh = tMesh;
myRenderer.material = new Material (Shader.Find(" Diffuse"));
}
Do keep in mind your triangle winding orders and the position of this new item relative to the camera (by default the above works but it creates a mesh rotated away from the camera so it’s not immediately visible to the default camera view.
Try the above to ensure that it works for you, then add the MeshFilter bits to your own code and see how that goes.
I’m trying to do something similar with SkinnedMeshRenderer, but can only get it to show up if I have a Meshfilter AND a Meshrenderer in the gameobject.