- Home /
Is it possible to fade individual game objects while maintaining material batching?
Hey there - idle question, which may or may not be dumb...
If I wanted an individual instance of a game object to fade out (examples: dead body, object exiting visibility range, scenery between camera and player avatar, floor and contents of building level above level with current focus) I would probably grab the object's materials in question (renderer.material, assuming it has alpha) and repeatedly assign a colour which I lerp the alpha on over the course of a third of a second or whatever. I could do this with a coroutine or an animation clip. (Description's a bit rough because I haven't done this in a while - as I say, it's an idle question)
However - if I want to maintain static and dynamic batching, I should in general avoid modifying renderer.material as this creates a new copy of the material, messing with the batching (and adding to memory usage). So there's a conflict there.
Obviously creating an object pool can help a little for enemies, etc, but as I say, sometimes you just want to fade out an arbitrary wall or other scenery if a player's behind it (again, ignoring solutions like having the player show x-ray like through the walls, or having the walls shrink in Y to show the player behind).
Does anybody have any best practice suggestions for having individual game objects fade out while maintaining material batching?
--Rev
Answer by tanoshimi · Jun 28, 2016 at 08:23 PM
Batched objects must share the same material. So, the only way I can think to adjust the alpha of a single gameobject with a shared material is to assign its opacity based on a vertex colour applied to the mesh. But, depending on how complex your mesh is, the cost of looping through and assigning a colour to each vertex might outweight the benefit saved from maintaining batching.
Yeah. Pretty much what I thought - if you want this effect, at some point you just have to go 'feck it' and eat the performance drop.
I did think that - given the fade time - it might make sense to store an array of materials at various alpha levels and on fade event iterate through 'em, but again, are you doing to do this for everything? No.
Wouldn't $$anonymous$$d hearing more about your vertex opacity scheme, but basically I think I have my answer. Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612083845im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fading out GUITexture - I need help with timer function that will control the speed of fading out 1 Answer
Multiple Meshes VS Armature 1 Answer
Fading from my splash screen 1 Answer
A question about draw call performance when it comes to unique texture use. 0 Answers
Fade in/out a GameObject 1 Answer