Bug fix

    void Start()
    {
        var pos = new Vector2(Screen.width, Screen.height);
        transform.position = Camera.main.ScreenToWorldPoint(pos);
    }

I try to run this piece of code attached to a rectangular Hotbar of dimensions 384x96, I’m using this script to try and make it so that no matter the resolution of the screen used, the Hotbar will snap perfectly into the bottom right corner (starting out just making it snap to what you see then fine-tuning it into the right place.
The script has no compiler errors or warnings, but when I run it, no matter how I change the values of Pos, the Hotbar always snaps to show the top right corner of itself on the bottom left of the screen, with the rest off to the side/bottom.

Any ideas on how to fix this greatly appreciated. (I’m gonna try for a tiny bit more and then sleep on this post)

Is this a UI element on a Canvas, or does it live in the game world?

If it’s a UI element there’s no need for any script at all. Just set the pivot to the bottom, right, anchor the thing to the bottom right of the screen and set the position to 0s all across.

1 Like

How Anchors work:
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/UIBasicLayout.html#anchors

Camera.ScreenToWorldPoint() relies on a nonzero Z value in the Vector3 argument you pass in.

You are using a Vector2 which has an implicit zero for Z.

See the documentation for why you need this: It’s the distance into the scene.

If you give it a zero, and it is a perspective camera, ANYWHERE you ask is going to be 0 units into the scene, ie. at the Camera itself.