Disappear/dissolve Effect at Run-time

Hello Everyone,

I am new to Unity and shaders so forgive me if this question is stupid, but I’ve searched for hours for an answer to this question, maybe I’m just not looking in the right places.

I have a dissolve effect I’m trying to apply to a character. This character has 3 different materials (arms, legs, and body) with different textures for each. I have duplicated each of the materials so I can assign the dissolve shader to them, and then I swap out the materials at run-time to perform the dissolve effect. However, in order to use 3 different textures within the shader I created 3 different shaders, one for each texture located in a Texture 2D asset.

I’ve searched for a way to perhaps generalize or simply my method as there is a lot of duplication, and if I want to add a weapon or something to the character, this method requires me to develop a new material as well as a new shader for every weapon and item I want to equip on my player. I can’t help but feel like this is the wrong way to go but I’m struggling to find a better solution.

Any suggestions or advice would be greatly appreciated.

I’m confused, why do you need a separate shader? The texture properties on a material can be arbitrarily assigned, so you should just need 3 materials, all using the same shader.

So I thought I needed separate shaders because I thought had to pull in each texture separately for the different materials. Eventually I realized I could create saved properties such as “_BaseMap” that would carry over from the universal shader. I ended up doing that, and now I swap the shader out when I want to perform the effect, although I’ve come across some posts where they say it’s not recommended to do that because of memory leak issues. However, the alternative seems to be to swap the materials, in which case though I would need a reference to all of the materials to swap them. It seems so much more convenient to just swap the shader on the materials, than to bring in new materials.

I think the original intent of the post is probably addressed at this point, though if you have any advice on what could I could be doing better, it would be much appreciated. Thank you for taking the time to respond to my post.

If you’re using the URP, make a new material, keep it around and reuse it or destroy it once you’re done with it. The memory issues come from when you make new materials constantly (like every frame) and don’t bother to destroy them afterwards. For example, if you set a material on .material vs on .sharedMaterial it makes a new material each time. And it can be very easy to get into bad patterns where you’re accidentally creating new materials when you don’t expect to because of that.