- Home /
Assigning SharedMesh is creating an unreferenced instance
I've been creating a database for game object parts. I have generic prefabs and I am giving them new materials and meshes based on type. The data base is a custom asset using scriptable objects and is organized as so: Database -> FamilyType (all share same material) -> UniquePiece (each have a unique mesh). Each level is a scriptable object so that later I can import and export parts of it.
The is all works great but the problem is the mesh on the new game objects. When I go to inspect the game object in the scene the MeshFilter shows that the mesh is Instanced and when I click on it sure enough it doesn't link back to the mesh in my assets. It works just fine for the material. I am putting it on SharedMesh on the MeshFilter just like the material for the renderer. I just don't know what is wrong! I've tried multiple things. Putting the material on the piece instead of family level to see if the same happened (didn't). Tried assigning the mesh after, before, not making a new piece reference, etc. Here is the code for making the new game object from the database and an image showing the mesh and material on the created game object.
public GameObject MakePiece(int family, int piece)
{
PieceInfo pieceInfo = families[family].pieces[piece];
GameObject newPiece = Instantiate(genericPiece[pieceInfo.genericIndex]) as GameObject;
newPiece.GetComponent<MeshFilter>().sharedMesh = pieceInfo.mesh;
newPiece.renderer.sharedMaterial = pieceInfo.mat;
newPiece.GetComponent<Block>().info = pieceInfo;
return newPiece;
}
So no solution to this problem? Perhaps it is a bug ... might move this over to Unity Forums and make a topic about it. Really frustrated that this is not working as it should (or at least I think it should, which is always the case isn't it).
Where are you grabbing the mesh in the PieceInfo class from? Remember, if at any point you have a meshfilter that you call .mesh on, you'll be generating a cloned instance of it, as specified in the docs. This is also the case if you're grabbing it from a meshfilter that's a part of a prefab.
@Baste, thanks for the response. I combed forums and found someone else that was having the same problem. Since it is a custom asset I set the mesh in the editor which is why I was confused to why it wasn't working. But it was just as you said. I had to go through each script to finally find it but there it was a reference to .mesh elsewhere ins$$anonymous$$d of .shared$$anonymous$$esh. A stupid mistake really and wouldn't have noticed it ever unless I was swapping meshes checking it. I'll probably delete the question since it is a non problem.
Your answer
Follow this Question
Related Questions
Selected Mesh in inspector is missing name, the link to mesh in assets is also missing 1 Answer
How Can I change the 3rd person controller Mesh? 2 Answers
Procedurally generated Mesh not updating? 1 Answer
Scriptable object keeps referencing the objects? 1 Answer
Scriptable Objects, how to force Include in Compile / Build without referencing it in the scene? 1 Answer