Hi!
Today I made an empty project, installed shader graph and LWRP, created a plane with a pure black material, and then I created two game objects with spriterenderers on them. I then proceeded to create a shader with shader graph that goes from one colour to another by changing a value from -100 to 100. I then put that shader on my two game objects, and created a GameController script that adds to the value if it’s between the parameters and F or G is held down (different button for different object), and subtracts from the value if it’s between the parameters and no buttons are held down. I lastly made a boolean that is set true if both values reach 100, and put it all in an if statement so that if the bool becomes true, it stops checking all of it.
I then pressed play and alternated between F and G to see if it all worked fine, and I got a lot of lag and eventually the “JobTempAlloc has allocations that are more than 4 frames old” error came up. I also checked profiler and it says there’s a total of 3700 objects, which sounds absurd.
Not sure what’s going on here, anyone got some experience with this?
public class GameController : MonoBehaviour
{
public GameObject rightArrow;
private SpriteRenderer rightShaderMat;
private float rightShaderInt;
public GameObject leftArrow;
private SpriteRenderer leftShaderMat;
private float leftShaderInt;
private bool bothFull = false;
// Start is called before the first frame update
void Start()
{
rightShaderMat = rightArrow.GetComponent<SpriteRenderer>();
leftShaderMat = leftArrow.GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update()
{
if (bothFull == false)
{
rightShaderInt = rightShaderMat.material.GetFloat("_Gradient");
if (Input.GetKey(KeyCode.G))
{
if (rightShaderInt < 110)
rightShaderMat.material.SetFloat("_Gradient", rightShaderInt + 1.5f);
}
else
{
if (rightShaderInt > -90)
rightShaderMat.material.SetFloat("_Gradient", rightShaderInt - 1.5f);
}
leftShaderInt = leftShaderMat.material.GetFloat("_Gradient");
if (Input.GetKey(KeyCode.F))
{
if (leftShaderInt < 110)
leftShaderMat.material.SetFloat("_Gradient", leftShaderInt + 1.5f);
} else
{
if (leftShaderInt > -90)
leftShaderMat.material.SetFloat("_Gradient", leftShaderInt - 1.5f);
}
if (rightShaderInt >= 100 && leftShaderInt >= 100)
{
bothFull = true;
}
}
}
}