- Home /
Query if MeshFilter is instantiated or shared?
Hello, I am doing some serious profiling and it would be really benificial if I could query wether or not a MeshFilter
is using .mesh
or .sharedMesh
.
So far I have not found anything helpful in that regard, maybe someone knows how?
Answer by lassade · Aug 19, 2016 at 10:49 PM
This is a good question! I made a sample project to see how you can check if your mesh is using a sharedMesh or its own mesh. Download the project here
Each unity object has its own instance id, so to check if two objects references the same you could compare their instance id. So in the sample I look for all MeshFilters active in the scene and add all sharedMesh instances ids into a HashSet to see how many different Meshes my scene has.
Note that if you want to see what mesh the MeshFilter is using you have to look at the sharedMesh property MeshFilter.mesh will return a clone of the sharedMesh, and it is used by my sample code to clone some meshes.
First of all, I'd like to thank you so much for taking all that time to make a project and answer throughly! It's pretty rare I get any answer for my questions, so really just a huge thanks <3
Now to the answer :) Thats a pretty nifty solution. I was actually looking at the problem in the wrong way. Thinking of each single object. But using instanceIDs is going to be perfect. I can drill down an object hierarchy and simply show how many unique shared$$anonymous$$esh IDs there are (which is pretty much what I'm looking for).
I quickly tested if the shared$$anonymous$$esh ID changed when instantiating a new mesh (accessing .mesh
) and it does. While doing those tests, I noticed the mesh name in the editor changes to "... Instance". So I guess you could also just search the name and see if it contains "Instance" hehe.
Well, that covers it and is going to be really useful! Thanks again :)
edit: I'll be using both techniques to show Total $$anonymous$$eshes and Instantiated $$anonymous$$eshes stats. I think that covers it.
Actually there's no need for using the objects instance IDs ^^. A dictionary also works with object references. So you can create a Dictionary with "$$anonymous$$esh" as key type.
Your answer
Follow this Question
Related Questions
Mesh memory leak error 0 Answers
difference between sharedMesh and Mesh 1 Answer
Is there any way to reset the default meshes? 3 Answers
Procedural Mesh problem from Editor Window 1 Answer
Mesh.vertices are all 0? 1 Answer