My question is what is the best way to handle fading of individual instance of GameObjects?
It is my understanding that when I instantiate a new clone of a GameObject Prefab - the sharedMesh property of the MeshFilter of all the instances will point to the same mesh, meaning that if I vertex colour that mesh then they will all fade together (for example) instead of individually as I’d like.
If, on the other hand I used the meshFilter.mesh property then it does work but every frame, for each GameObject I’m creating a new mesh and these don’t seem to be well cleaned up. I.e. the number of meshes in my scene on the profiler goes through the roof and on IOS devices the game starts to stutter from garbage collection.
I was previously using the material colour to fade them, but that had the same problem - i.e. loads of materials being created etc…
(and breaks batching)
I do have a solution that works, I just have the feeling there must be a better way. So, in a script, not attached to the GameObject, but containing that gameObject - so responsible for Instantiating it etc… I create a mesh. When I instantiate a gameObject there I copy its sharedMesh and then store a pointer to my mesh in the .sharedMesh property of the MeshFilter. And then i perform the vertex colouring on the sharedMesh.
So there is only ever one per Instantiated GameObject.
I should say that there are lots of these GameObject’s appearing and being destroyed all the time. Kindof Particly…
so, any hints on where i’m being particularly dim here?
Thanks