I am downscaling the resolution of my game by 25%. The issue is that after I set the resolution to the new values, the device remembers the new resolution even after I uninstall the game. Then the “default resolution” is the downscaled number from previous builds, so it gets downsclaed twice.
I am scaling resolution with
Screen.SetResolution(Screen.currentResolution.width * 0.25f, Screen.currentResolution.height * 0.25f
I have tried the following:
- Updated my android manifest with
android:allowBackup="false"
- Updated my android manifest with
android:fullBackupOnly="false"
- Deleted all player prefs through code on the device.
However when I build with airplane mode ON, the device is as the correct native resolution, so when it gets downscaled, it is correct.
Has anyone encountered this problem before and if so how do you fix it?
@cyborgjinx Sorry about that comment, I was sure I used that early in my project
Here is solution tested on android build, just added this to my current game.
So, for testing just build simple canvas with 4 buttons and one text object, then for buttons set functions as on picture and it will show difference between functions.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Resolutions : MonoBehaviour
{
public float multip = 0.9f;
private Vector2 screenSize;
public Text resText;
public void SetFromResolution()
{
screenSize = new Vector2(Screen.width, Screen.height);
Screen.SetResolution(Mathf.CeilToInt(screenSize.x * multip), Mathf.CeilToInt(screenSize.y * multip), true);
}
public void SetFromCurrentResolution()
{
screenSize = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
Screen.SetResolution(Mathf.CeilToInt(screenSize.x * multip), Mathf.CeilToInt(screenSize.y * multip), true);
}
public void SetFromDisplayResolution()
{
screenSize = new Vector2(Display.main.systemWidth, Display.main.systemHeight);
Screen.SetResolution(Mathf.CeilToInt(screenSize.x * multip), Mathf.CeilToInt(screenSize.y * multip), true);
}
public void RestoreResolution() // put your device resolution you know for test
{
Screen.SetResolution(1920, 1080, true);
}
// Start is called before the first frame update
void Start()
{
}
private void Update()
{
// because set resolution takes some time text wasn't updating correctly
resText.text = "X: " + Screen.currentResolution.width + "; Y: " + Screen.currentResolution.height;
}
}
Cheers,
Kamil