U
U
Uncle Bogdan2022-04-12 18:20:13
Unity
Uncle Bogdan, 2022-04-12 18:20:13

Do SkinnedMesh and MeshFilter have some common descendant?

Hello! I am making a building system and the player can put houses or fighters on the map. When a player places an object, the cursor point shows how the placed object will look like. To show the delivered object I change the mesh.

To show the house I do it like this:

MeshFilter.mesh = BuildingPrefab.Value.MeshFilter.sharedMesh;


Everything works fine, but the character has a SkinnedMeshRenderer component instead of the MeshFilter component, and to get a mesh from such an object, you need to write:

MeshFilter.mesh = BuildingPrefab.Value.SkinnedMeshRenderer.sharedMesh;


That is, to get a mesh from a love object, you need to write:

MeshFilter.mesh = BuildingPrefab.Value.MeshFilter != null ? 
                    
BuildingPrefab.Value.MeshFilter.sharedMesh : 

MeshFilter.mesh = BuildingPrefab.Value.SkinnedMeshRenderer.sharedMesh;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question