Hey guys, I am having a tough time figuring out how to move an element from the ui canvas in screen overlay mode based on the position of an object in the game world space. I’ve seen a lot of examples but I can’t seem to figure it out. Nothing I have done manages to move the position at all.
This is the line I currently have that is supposed to get the world position and move the textbox/speechbubble to that position. Even if the conversion of the positions is wrong that’s fine, but at least I could confirm that I have indeed managed to move the speech bubble. But I can’t even get it to move at all.
// cameraController.ScreenCam is the reference to the Camera instance in the active scene
BanterBubble.GetComponent<RectTransform>().position = cameraController.ScreenCam.WorldToScreenPoint(t.position);
Can someone explain to me what I am doing wrong? Or point me in the right direction to some material that would help me?
I’ve tried position & localPosition, at this point I just have no idea. It would seem to me that this would be how to set the position of something and it should reflect it in the game world. Even confirming that this is how to make it move would be helpful as then I would assume something in a parent is anchoring or locking it’s position and overriding this line.
So I was able to confirm it’s working correctly (or mostly) and that my issue was the camera reference was not being assigned properly in some scenes due to how I was getting the reference. I broke this code a while back making a change and forgetting to test this particular edge case. I figured I’d leave this up in case anyone stumbles upon it. As this code does work and if you see this:
MAKE SURE TO DEBUG AND CHECK THAT THE OBJECT IS ACTUALLY RETURNING A TRANSFORM AND POSITION!