noAlphabet
noAlphabet

Reputation: 5

Unity build not building game correctly

So when I tried to build my unity project the options menu did not build correctly. I tried two unity version, a hard restart of my system, and changing settings. Nothing corrected the issue. The game works fine in the unity editor but does not work correctly when built.

Editor drop-down (How it should be): Here

Build drop-down (How it should not be): Here

If you look in the build picture it duplicates all the drop-down entries which may be cause by the script that generates it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;

public class OptionsMenu : MonoBehaviour
{
    public AudioMixer audioMixer;
    public Dropdown resolutionDropdown;

    Resolution[] resolutions;

    void Start()
    {
        resolutions = Screen.resolutions;
        resolutionDropdown.ClearOptions();

        List<string> options = new List<string>();

        int currentResolutionIndex = 0;
        for (int i = 0; i < resolutions.Length; i++)
        {
            string option = resolutions[i].width + "X" + resolutions[i].height;
            options.Add(option);

            if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
            {
                currentResolutionIndex = i;
            }
        }

        resolutionDropdown.AddOptions(options);
        resolutionDropdown.value = currentResolutionIndex;
        resolutionDropdown.RefreshShownValue();

The other problem is with the quality dropdown, In the editor it works fine but when I build it it does not change the game quality (It stays on low).

The other problem has only occurred on one build. The problem was that the mouse sensitivity to move the camera was very low, when I built it again the problem was fixed.

Upvotes: 0

Views: 1773

Answers (1)

Deleter
Deleter

Reputation: 780

For duplicates, it's a known problem: the problem is on standalone where it appears to duplicate each resolution with refresh rates of 60Hz and 48Hz.

For example: 640x480@48Hz; 640x480@60Hz; etc

A solution could be a Linq statement, selecting only 60Hz frequencies (or 48Hz):

var resolutionsIEnumerable = Screen.resolutions.Where(resolution => resolution.refreshRate == 60);
resolutions = resolutionsIEnumerable.toArray();

Linq Where() returns IEnumerable so, you have to convert to array Resolution[] (with toArray())

In order to change resolution, you have to use

Screen.SetResolution(640, 480, true, 60);

You should change 640 and 480 on dropdown change with the selected resolution.

Upvotes: 1

Related Questions