I have a User Interface I am working on. I have my Canvas set to “Screen Space - Overlay”
Within that UI, I have a GameObject nested many levels deep inside other game objects. I want to find the Vector3 transform (it’s location) of that specific object in Global Screen Space.
Currency if I try and print out the objects position :
Debug.Log(myObject.gameObject.transform.position)
I am getting : (12.3, 254.0, 0.0)
Yet this GameObject is roughly in the center of the screen. I am assuming that’s it’s position relative to it’s parent.
How can I get it’s position relative to the canvas screen (which is set to 1920x1080)
I’m hoping to get a position of something like (950, 500, 0.0)
I feel like ‘WorldToScreenPoint’ or anything like that is the wrong method. At the end of the day, I just want to convert local screen space to global screen space. I’m struggling to locate the answer on google… hoping someone knows the answer
Worst case scenario I loop through a game objects parents (recursively to the root) and calculate where it is in the global screen space… but there must be a method already provided to do this. I can’t seem to find the answer anywhere
Bro, I feel you. Could you finish your worst-case scenario method?
I’m also that far to write a recursive method to find position, but am really afraid of all the unknwos lurking doing that.
transform.position does give the global position on the canvas.
Ex: If you had another object nested deep within others, and then one at the top level. Setting it’s transform.position to the one nested deep would place it right on top of it.
Keep in mind the Anchors and Pivots matter, so for best results set them to top left, or bottom left.
I ignored this option because I thought you had to supply the camera (which isn’t possible while using overlay) but actually you don’t need to add the camera as third option when you’re using overlay.