Hey Chris, sorry for all the recent questions about the Options menu. I noticed that the APPLY button in GraphicOptions is missing its On Click setting, which is causing the resolution settings not to be applied. I don’t think I’ve changed any of the settings, but they currently look like this:
https://prnt.sc/HwNtpKnqdnAO
https://prnt.sc/czo2oMGtBcpA
I have another question regarding the screen resolution settings. At the moment, it shows a lot of unnecessary resolutions. How can I limit it to only display 16:9 resolutions? I tried removing the supported aspect ratios 1.6 and 2.333333 from the prefab, but that caused all resolutions to disappear.
https://prnt.sc/ieQVMh-1jcAJ
And if I use my own script, will it conflict with AC? I’m planning to use the script below which applies the setting as soon as it’s selected.
P.S. I only plan to use Resolution dropdown and Full Screen toggle.
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Linq;
using System.Collections.Generic;
namespace AC.Templates.GraphicOptions
{
public class GraphicOptionsUI : MonoBehaviour
{
[Header("UI References")]
public TMP_Dropdown resolutionDropdown;
public Toggle fullscreenToggle;
private List<(int w, int h)> allowedResolutions = new List<(int w, int h)>();
private int currentResolutionIndex;
// Allowed fixed resolutions
private readonly (int w, int h)[] targetResolutions =
{
(1280, 720), // 720p
(1920, 1080), // 1080p
(2560, 1440), // 1440p / 2K
(3840, 2160) // 4K
};
private void OnEnable()
{
PopulateResolutionDropdown();
LoadSettings();
// Auto-apply when changing
resolutionDropdown.onValueChanged.AddListener(delegate { ApplyResolution(); });
fullscreenToggle.onValueChanged.AddListener(delegate { ApplyResolution(); });
}
private void OnDisable()
{
resolutionDropdown.onValueChanged.RemoveAllListeners();
fullscreenToggle.onValueChanged.RemoveAllListeners();
}
private void PopulateResolutionDropdown()
{
resolutionDropdown.ClearOptions();
allowedResolutions.Clear();
Resolution[] allModes = Screen.resolutions;
foreach (var target in targetResolutions)
{
// If monitor supports OR we want to show it anyway
bool supported = allModes.Any(r => r.width == target.w && r.height == target.h);
if (supported || target.w >= 2560) // Always show 2K+
{
allowedResolutions.Add(target);
}
}
var options = allowedResolutions.Select(r => $"{r.w} x {r.h}").ToList();
resolutionDropdown.AddOptions(options);
}
private void ApplyResolution()
{
currentResolutionIndex = resolutionDropdown.value;
var chosen = allowedResolutions[currentResolutionIndex];
bool isFullscreen = fullscreenToggle.isOn;
int refresh = 144; // lock at 144 Hz
// Force reapply even if fullscreen state is unchanged
Screen.fullScreen = !isFullscreen; // temporary toggle
Screen.fullScreen = isFullscreen;
Screen.SetResolution(chosen.w, chosen.h, isFullscreen, refresh);
SaveSettings();
Debug.Log($"Applied: {chosen.w}x{chosen.h} @144Hz Fullscreen:{isFullscreen}");
}
private void SaveSettings()
{
PlayerPrefs.SetInt("ResolutionIndex", currentResolutionIndex);
PlayerPrefs.SetInt("Fullscreen", fullscreenToggle.isOn ? 1 : 0);
}
private void LoadSettings()
{
currentResolutionIndex = PlayerPrefs.GetInt("ResolutionIndex", GetDefaultResolutionIndex());
fullscreenToggle.isOn = PlayerPrefs.GetInt("Fullscreen", Screen.fullScreen ? 1 : 0) == 1;
if (currentResolutionIndex >= 0 && currentResolutionIndex < allowedResolutions.Count)
resolutionDropdown.value = currentResolutionIndex;
else
resolutionDropdown.value = GetDefaultResolutionIndex();
resolutionDropdown.RefreshShownValue();
}
private int GetDefaultResolutionIndex()
{
for (int i = 0; i < allowedResolutions.Count; i++)
{
if (allowedResolutions[i].w == Screen.currentResolution.width &&
allowedResolutions[i].h == Screen.currentResolution.height)
{
return i;
}
}
return 0; // Default to first available
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
The script above has the same class name and namespace as the script used by the template. Did you replace the contents of the same file? The Button and ActionList reference functions in the script named SaveAndApply and Apply respectively - if you've replaced the script that they reference with the above, they won't have functions to call.
The script and template overlap in functionality. You can use your script with AC, but not alongside the template.
Yes, the same class name and namespace have been used in the new script. The new script appears to be working fine so I will relay on it instead of the AC version.