If I literally just click and drag round some sprites to move them all, they instantly all change to sharing one material?!
How can I stop this behaviour? (5.1.2f1 for PS4)
If I literally just click and drag round some sprites to move them all, they instantly all change to sharing one material?!
How can I stop this behaviour? (5.1.2f1 for PS4)
Wow, that is a ridiculous bug
I can’t believe it but the only thing I could come up with is this:
using UnityEngine;
[ExecuteInEditMode]
public class MaterialForcer : MonoBehaviour
{
public Material forcedMaterial;
void Update()
{
RefreshMaterial();
}
public void RefreshMaterial ()
{
GetComponent<Renderer>().sharedMaterial = forcedMaterial;
}
}
Put that on every sprite and put the desired material in forcedMaterial. This will work both in play and edit mode and won’t be necessary anymore once you’ve finished the game and are ready to build, just remember to remove it then. If you have a bunch of sprites and notice a drop in performance, you can make them refresh less often with a counter or something in play mode only, something like:
int counter = 0;
void Update()
{
if(Application.isPlaying)
{
if(counter > 9)
{
RefreshMaterial();
counter = 0;
}
else
{
counter++;
}
}
else
{
RefreshMaterial();
}
}
When you’ve finished the project you can run something like this to clean up, coming out of play mode once with this on a gameobject is enough:
using UnityEngine;
[ExecuteInEditMode]
public class Suicide : MonoBehaviour
{
void Start ()
{
foreach (MaterialForcer materialForcer in FindObjectsOfType<MaterialForcer>())
{
DestroyImmediate(materialForcer);
}
}
}
Someone should put this bug in the issue tracker, if it’s not there already