Search Unity

dynamic gui list help! [JS]

Discussion in 'Scripting' started by ackley14, Jul 2, 2015.

  1. ackley14

    ackley14

    Joined:
    Oct 31, 2014
    Posts:
    31
    hey! so im working on a console for a project and the best (easiest least code) method i've found without getting a plugin for this is using an array, filling it with stuff (log output) and pushing it to a dynamic GUI list in the form of a for loop based on how many elements are in the array. now here's the problem, i can only have about 25 objects in the array before the game starts dropping in frame rate. at about 50 items, im down to 30 (from 70). which is as im sure you can immagine very annoying. so what is the best way to go about having a dynamic list using unity's built in GUI system?

    here's my draw code :
    Code (JavaScript):
    1. GUI.Box(Rect(10,648-260,420,220),"Debug Log");
    2.             DebugBar = GUI.BeginScrollView (Rect (10, 648-240, 420, 200), DebugBar, Rect (0, 0,400, outputArray.length*25+15));
    3.          
    4.             for(i = 0; i<outputArray.length; i++){
    5.         GUI.Button(Rect(10,i*25+15,380,25),outputArray[i] + " |" +i +"|" );
    6. }
    7.  
    8.     GUI.EndScrollView();
    9.     }
    to fill the array im just saving the game to call the save notification.
    i've checked the profiler and it is comming from this script so i know its nothing to do with saves by the way.

    thanks for any and all help!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    are you particularly attached to the old legacy GUI approach? the newer UI came out in 4.6 and it does dynamic content much more simply
     
  3. ackley14

    ackley14

    Joined:
    Oct 31, 2014
    Posts:
    31
    not at all im just not sure how the new system works and if it will be more or less verbose :O
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    new system is less verbose on the scripting side, more "build in scene view" like the rest of unity. For example, to get a grid of elements you would just have a panel (UI gameobject) with a GridLayout component and add in whatever you want in the grid as children.

    I have no idea if the new system will solve your performance issues though, but unity seems to be going in that direction so it might be worth looking into the learn section UI tutorials as a primer.