com.unity.perception icon indicating copy to clipboard operation
com.unity.perception copied to clipboard

Unity perception won't allow changing resolution at runtime

Open calingc opened this issue 2 years ago • 3 comments

Hi, first of all congratulations on releasing the 1.0.0, it's really neat!

I have an issue I was hoping you might be able to help me with: We're using unity to generate synthetic data at scale. For that we have docker containers that run on VMs for which we create virtual displays (so we can render). However we're getting issues with changing the resolution. Basically the player build takes the default resolution set in Edit -> Project Settings -> Player -> Resolution and Presentation, but calling Screen.SetResolution(WIDTH, HEIGHT, false) at runtime won't change the resolution of the images or the masks we're generating. I've also noticed different behaviours between package versions:

  • perception 0.9 = images generated at the right resolution (the one set with Screen.SetResolution), but masks are rendered at the player build default resolution
  • perception 1.0 = both images and masks are generated at the player build default resolution

This is quite annoying as we need to create different builds where we hardcode the default width and height just so we can generate at different resolutions.

Also, this is not an issue if we're generating locally - having an actual display - Screen.SetResolution will actually work.

Do you know any solution/workaround for this? Any help would be greatly appreciated!

calingc avatar Jan 12 '23 12:01 calingc

I forgot to mention we're using Unity 2021.3.15f1, upgrading to 2022.* didn't change the above behaviour.

calingc avatar Jan 12 '23 12:01 calingc

Hi, You should be able to achieve this by rendering your camera to a render texture, and setting the resolution of the texture to your desired value. This should be done in a script that runs before anything else, which can be dictated through the DefaultExecutionOrder class attribute. For example, put [DefaultExecutionOrder(-1000)] before your class definition.

mkamalza avatar Jan 12 '23 17:01 mkamalza

Thanks, I'll try it out!

calingc avatar Jan 13 '23 10:01 calingc