Is there a callback that’s fired before a ui element is rendered? I’d like to adjust the elements position just before rendering.
OnWillRenderObject would be great, but it only works for non ui elements.
Is there a callback that’s fired before a ui element is rendered? I’d like to adjust the elements position just before rendering.
OnWillRenderObject would be great, but it only works for non ui elements.
There any reason for not just using Update/LateUpdate? That’s in step with the actual frames of the game, so no matter what, it’ll always be called before a frame is rendered.
Otherwise, is OnGUI what you’re looking for?
I need to snap ui elements to integer positions. I found an example of someone doing this with OnWillRenderObject and OnRenderObject, which seemed nice and straightfoward until I found Unity doesn’t fire OnWillRenderObject for canvas objects. It requires two callbacks so you can move the element back to it’s original postion after being rendered.
Doing this sort of thing in Update will mess up the positions of everything.
OnGUI is horrible and should not be used for anything ![]()
I wonder if a shader would be a better solution for this?
Yeah, you’re probably right. I know Unity’s sprite shader has a ‘pixel snap’ option but it doesn’t work for me. Will look at implementing my own shader based solution.
So sorry for the semi-necro, but it’s only been a week so whatever.
I’ve just come across some old code in one of my projects that uses OnPostRender. It’s been a long time since I wrote it so it never even occured to me. After a look at the documentation there’s also OnPreRender. If you haven’t gone the shader method (or found these already by now), those might be what you want.