Screen.width Windows Unity issues

Screen.width Windows Unity issues:

I have a variable I’m assigning the Screen.width to and it’s showing a value of 268 when it should be reading 1024.

The Screen.height is working as expected. Has anyone else ran into this issue ? :frowning:

And is their a workaround for it.

Haven’t come across that one before, I work on Vista 64 Ultimate.

Is this running at full screen, or windowed in the editor you get this issue? Also check the stats display if you are working in the editor and see what it’s width is displaying.

When I hit the stats button its showing screen resolution is:
963x541

I just have this script assigned to an empty object.

var EdHeight = (Screen.height);
var EdWidth = (Screen.width);

And the variables are reading:

EdHeight 770

EdWidth 270

And I have no idea why???

Weird it seems to be an issue with the script editor I was using (ConTEXT).

I switched to the default script editor and now the variables are reading the proper values.

Ok I spoke to soon this is a bug with Unity and Xp.

I removed Context and used the default script editor and things were fine. Then today when I woke up the weird screen.width issue is back.

Even though I haven’t changed a single thing.

My screen is width is saying its less then a 1/3 of what it actually is. :frowning:

That is strange. I’d give the usual “Latest Graphics Drivers” advice, and also try to pin down what else happened when you switch to using the other text editor. Maybe it was a recompile of the scripts that triggered it to work or something like that.

Yeah the drivers and OS are up to date. I do CG for a living so I’m pretty good about that sort of thing.

I guess I need to figure out some work around using screen.resolution.

Old thread, but I’m having the same issue. Height is working fine, but Width is showing up way too small.

This already happened to me.

Screen.width and Screen.height doesn’t return the resolution the user/developer picked, but the actual window/screen size.
Are you stretching the editor’s game window? That could be the cause.

Hope it helps!

When you are checking it, are you checking during the Start() or in Update() ? If youre checking in Start() you will get the screen width in the editor at the time you pressed play. If you check it during Update() you will get the width even if you stretch it.

Not sure much else to tell you.

For me, it’s returning the same number no matter what resolution. Screen.height is working properly, but not Screen.width. The variable set as public, so it shows in the inspector.

There is a known bug that occurs when a project is run in the editor - the correct value of Screen.width and Screen.height don’t get set until a few frames into execution. As far as we know, it doesn’t happen in built applications or webplayers but it can be a bit of a nuisance during development.

Correct – I have noticed this. I am currently developing a game for the web with a set resolution. Luckily the resolution is small, 800 x 450 or something, meaning it can fit on all of my screen at once. If I press play while in scene mode (AKA, where you “build your world”), my GUI gets messed up because Unity gets the screen resolution before game mode (where you play your game in the editor) fully starts.

My suggestion would be use a low resolution in the editor, manually click on the game mode tab and then press play. I was tearing my hair out until someone at Unity support told me this. Hope it gets fixed in the next patch.

I had the same problem with a stand alone build as well. I can see the variable for width being set in the inspector when I attach the script.

I know this is an old thread but I was having the same problem so hopefully this can help someone.

I was trying to get the Screen.width and Screen.height in editor mode and it was being reported wrong. I was able to get around this by using ExecuteInEditMode and checking the screen dimensions in the Update() loop and it appears to work fine.

Greetings from The FUUUUUUUTUREEEEEEE, a decade hence!

This was the solution for me… I had to capture width and height in the update loop, and provide that to my editor script.

Thanks!

1 Like