- Home /
How to update ScreenToWorldPoint before Camera renders?
Let's say I'm trying to temporarily change a camera's position/rotation or projection matrix so that within the same frame I can use ScreenToWorldPoint
to calculate things based on the temporary changes to the Camera. I want to later revert these changes (again, in the same frame) before rendering. These results would then be used over, say, the next second to accomplish my task.
However, it seems that things are not updated until the Camera renders. I've tried using .CopyTo
to create a new Camera and get the information from there, but that doesn't work. Nor do ResetWorldToCameraMatrix
or ResetProjectionMatrix
. Can anyone offer any insight?
Answer by Patel-Sagar · Mar 26, 2014 at 12:09 PM
I tried one thing...
my camera is at (0,0,0) and one cube is at (0,0,5). so distance between two should be 5.
Now in LateUpdate() I changed camera position to (0,0,1). NOTE: LateUpdate() is called after Camera.Render(). then in OnPreRender() I print distance between cube and camera.after that I changed camera position back to (0,0,0).
Result: distance in output is 4. but in scene rendering camera is always stays at (0,0,0).
In Short: in LateUpdate() : Do changes into Camera Do anything between this. in OnPreRender() : revert changes into Camera
Thanks -- this was helpful in figuring out the ordering. I managed to fix my problem by changing what I was trying to do.
please mark answer as correct and vote up if you are satisfied with my answer.
Your answer
![](https://koobas.hobune.stream/wayback/20220613141150im_/https://answers.unity.com/themes/thub/images/avi.jpg)