Search Unity

List<> don't populate?

Discussion in 'Scripting' started by Kovenant, Apr 30, 2017.

  1. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    I have this script which should populate a List<> with supported screen resolutions.
    It works when I haven't checked "Maximize On Play".. why is that? I've tried to add Debug.Log for each resolution in the foreach-loop, but the Debug.Log doesn't output anything if Maximize On Play is checked, however it does when I haven't checked it..

    Anyone with the same problem and knows a "quick fix" for this?

    I'm using Unity 2017.1.0b2

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class ResolutionsOptions : MonoBehaviour {
    7.  
    8.     public UISelectField m_SelectField;
    9.     private List<string> m_Resolutions = new List<string>();
    10.  
    11.     private void Start()
    12.     {
    13.         Resolution[] resolutions = Screen.resolutions;
    14.         foreach(Resolution res in resolutions)
    15.         {
    16.             m_Resolutions.Add(res.width + "x" + res.height);
    17.             Debug.Log(res.width + "x" + res.height);
    18.         }
    19.  
    20.         m_SelectField.options = m_Resolutions;
    21.     }
    22. }
    23.  
    (I have reported a bug, but not sure this is related to the editor or if I'm doing something wrong...)?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If it works without Maximize on play, and you make a quick build and it works in general, I couldn't say if it's a bug or by design, but at least you'd know that it's just a small quirk to remember when using that :)
    Maybe the resolution options are disabled in that mode or something.
     
    Kovenant likes this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Resolutions reports weird things in the editor. It's a quirk to know about an live with.

    Most resolution things need to be done in builds on the target device.