this is the code I use, and can’t seem to figure out a way to avoid GC, and would like to know if it even is possible or GC is just something that comes with altering outline.
Modifying the material property directly on the instanced material is definitely the correct approach.
Are you modifying the outline width on a single text object or doing so on multiple text objects?
If multiple text objects, is this being updated independently on each text object? If you are modifying multiple text objects all at the same time, I would try to use a common material instance as opposed to creating a new material instance per text object.
Without having a better understanding of your needs it is hard to provide more insight but again modifying the material property directly is the better route.
Multiple, but each with different outline parameters ? each has this script attached.
“Modifying the material property directly on the instanced material is definitely the correct approach.”
So the structure of the code is good? when desired outline is reached (max or min), I update objectTMP.UpdateMeshPadding(); and on each Update() tick adjust the outline via instance of the material with tmpMaterial.SetFloat(ShaderUtilities.ID_OutlineWidth, currentOutline);
The mesh padding needs to be updated when the outline grows in size to make sure it remains visible. So in theory, you should not have to keep updating it once you have reached the max size for example. I would suggest experimenting with this on your end.
It should be updated on every increase leading to the max. Alternatively, you could enable Extra Mesh Padding in the Extra Settings of the text object. Depending on the Sampling Point Size to Padding ratio, this could give you enable padding range but you will need to test that.
Note: We are just talking potential added optimization here.