Hey everyone!
I am currently stuck with an issue. I am using WorldToScreenPoint to move waypoints, healthbars, and timers to match that of a real world position. However, there seems to be a serious issue with this method. If I turn my camera, the UI will not follow quickly enough to maintain the proper position of the UI elements. You can see it here in this GIF:
gloriousleafycaterpillar
Things I have tried:
I am using LateUpdate, I have tried resetting my camera matrix before moving the UI, I’ve lowered my script that controls the UI to execute below the script that moves my camera, I have tried using both SetPositionAndRotation as well as just setting the position manually, AND I have tried forcing the UI to update after rendering. Nothing works.
(Just to show what I have, the ac_CharacterController script moves my camera, and the CrosshairScript moves the UI)
Things I’d like to avoid:
If possible, I’d like to avoid using multiple canvases per object. I use a separate canvas for the waypoints, healthbars, and timers anyway since updating my canvas with more stuff on it would be useless for my HUD. However, I don’t want to have to use multiple worldspace canvases since I want these UI objects to show through walls (and I think having 300 canvases would probably be less performant than just having one canvas that pools the same UI when necessary).
Some details on the bug:
-
The closer I get to the object the UI is meant to position on, the worse the lag becomes
-
The lower the framerate, the worse the lag becomes
-
It is not as prominent in Build, but it is still very much there (the GIF I recorded was from Build)
-
No other scripts are interacting with the UI or position of the object, it is static (unstatic doesn’t change results)
-
No other scripts are interacting with the canvas
The code:
----------------------------------------
Vector3 Position = MainCamera.WorldToScreenPoint(TargetPosition.transform.position);
Timer.rectTransform.SetPositionAndRotation(Position, Quaternion.identity);
----------------------------------------
I am really REALLY stuck here, and I would greatly appreciate someone working with me to find a solution to this. I have to push an update to my game here soon, and I really don’t want to update it with something this glaring in the game.
Thanks!