Git material spam

Hi all, we noticed that material changes in Unity are constantly picked up by our version control (Git). Even though we do not want to full ignore files is there another way to have material changes no be picked up or reverted after play mode. I know the materials are and asset but would be nice if there was a way we don’t know about :smile:

Materials normally don’t change by themselves. Whenever I see that problem in the projects I’ve worked on is because they are not properly modified via code during runtime. Depending on if you are accessing the material or the sharedMaterial property, you will be editing an instance of the material, or the asset itself. Ideally you should be editing the material property, or manually create an instance of the material, or use MaterialPropertyBlock.

Note that I don’t know if this is the cause in your case, but that’s what I would check before recurring to ignoring materials in GIT.

If you access data in assets during play mode, those can be immediately serialized, and yes, this will be picked by git.

To avoid that with materials, either clone materials, when needed (done automaticlaly, when you touch .material and not .sharedMaterial, though that’s probably not what you want), or override parameters using MaterialPropertyBlock.

https://thomasmountainborn.com/2016/05/25/materialpropertyblocks/

Thanks both I know about the fact that playmode changes materials. But the thing is I don’t change / access most of the materials showing up in git. It seems to be some binary changes. I will try and use the property blocks however!

If you’re using git, it may be a good idea to set asset serialization mode to “force text”
https://docs.unity3d.com/2017.3/Documentation/Manual/class-EditorManager.html

This way you’ll see what is changing.

In text mode, assets are yaml files.