Greetings, I’m trying to get the screen space position of a game object I’m rendering in my UI, the object is not properly on my canvas (which is a Screen Space - Camera) so what I’m doing is
var point = Viewer.Scene.camera.WorldToScreenPoint(myObject.transform.position);
Vector2 finalPosition;
RectTransformUtility.ScreenPointToLocalPointInRectangle(Viewer.rectTransform, point, Camera.main, out finalPosition);
I’m calling these lines from a panel inside the canvas, this panel can scale to fullscreen and back, when in fullscreen it has the screen size and localScale = Vector3.one but when it’s not it has different sizes, can be any size or scale. My issue is that when it’s not fullscreen the variable finalPosition and also the screen position are completely wrong, what am I missing?
@eses
Sadly this is not what I’m faced with.
I’ll explain a bit more, the point I want to check is not inside my canvas, it’s in a world position like (3794.6, 0.0, 3839.1), when I want to see where it is on my canvas with the lines I wrote I get that it’s actually in (-40.3, 290.2). I’m then using a secondary camera to get the raw image of this point and placing said raw image on my actual ui canvas. So transform.position of my point would always return me what I wrote before.