Screenspace UI not working after build (MacOS)

I’ve used some screen space position calculations ( e.g. Camera.main.WorldToScreenPoint ) to animate/tween my UI. Everything works great when I press play in the editor preview. But when I build and run it on mac, the positions are off.

The canvas Render Mode is set to Screen Space - Camera. I’ve played around with the player settings for PC, Mac, Linux and have tried using windowed vs fullscreen mode. The problem persists.

Notably, the screen space animations appear to be off by a consistent distance. As if something in the positioning math changes when playing in the editor preview vs playing a build.

Has anyone experienced a similar issue?

After posting this, I found a workaround. Still not a perfect fix but some more fiddling might get it there.

The problem was related to the Canvas Scaler component of the canvas object. There are two relevant properties: the UI Scale Mode and the Screen Match Mode.

Setting the UI Scale Mode to Constant Pixel Size resolved the misaligned screen space positions. But it doesn’t scale to a device screen size or window size and instead just crops the UI view. So it won’t work across multiple devices.

Setting the UI Scale Mode to Scale with Screen Size gives the options to change the Screen Match Mode. I had originally set this to Match Width or Height and that was causing my screen space issues. Changing this to Expand or Shrink solves this, but again this only works when the resolution I build for matches the Reference Resolution I choose in the Canvas Scaler component. The screen space positions will be off on other screen/window sizes.

It seems the screen space positions just do not scale properly across different screen/window sizes. Keep that in mind if you are using WorldToScreenPoint or any other screen space methods.

My guess is that the best option if you intend to use screen space positions is to hard code a scaler that takes in the screen width/height in pixels and adjusts the position accordingly.