Hello,
I’m trying to override the function that unity calls for drawing GameObject’s to the screen.
I want this so I can change values in the shader just before the object is drawn.
Right now I have this:
void Update () {
renderer.sharedMaterial.SetVector("center", new Vector4(transform.position.x, transform.position.y, 0, 0));
}
But since Update() is called for all GameObject’s before any are drawn, only the last updated GameObject has the correct value for “center”
Any help would be appreciated,
To get things to draw correctly, use ‘material’ rather than the ‘sharedMaterial’.
renderer.material.SetVector("center", new Vector4(transform.position.x, transform.position.y, 0, 0));
I assume you are using ‘sharedMaterial’ to avoid drawcalls. If so, even if you could someone figure out how to do what you ask, the results would be the same. That is, you will need to change the value before each object is drawn, so the objects could no longer be batched together and sent to the GPU (and I’m unaware of any way to make your approach work in Unity).