GUIWindow slows down game by 30-50 FPS

hey i have a sidebar for a networked car game which gets information from each car like name, player, current lap. When i disable the script in game it goes up by about 30-50 FPS. any help on how to speed this up would be cool

using UnityEngine;
using System.Collections;

public class VehicleGUI : MonoBehaviour
{
    public GUISkin aGUISkin;

    private int maxVehiclesInRace = 8;

    private GameObject[] vehicleInRace;
    private VehicleCurrentRaceStats[] vehicleInRaceStats;

    private Rect guiRect;

    private float fltScrollerValue = 0.5f;

    void Awake()
    {
        guiRect = new Rect(0, 100, 200, 400);

        vehicleInRace = new GameObject[maxVehiclesInRace];
        vehicleInRaceStats = new VehicleCurrentRaceStats[vehicleInRace.Length];
    }

    void OnGUI()
    {
        GUI.skin = aGUISkin;
        guiRect = GUI.Window(0, guiRect, Sidebar, "RACE SATS", GUI.skin.GetStyle("window"));

    }

    void Sidebar(int windowID)
    {
        GUILayout.BeginVertical();
        GUILayout.Label("VEHICLES");
        GUILayout.Space(8);
        GUILayout.TextArea("PLACE - race position" + "\nNAME " + vehicleInRaceStats[0].racerName + "\nVEHICLE " + vehicleInRaceStats[0].tag + "\nCURRENT LAP " + vehicleInRaceStats[0].currentLap);
        
        //Scrollbars
        //fltScrollerValue = GUILayout.VerticalScrollbar(fltScrollerValue, 0.1f, 0.0f, 1.1f, GUILayout.Height(90));
        GUILayout.EndVertical();
    }

    void AddCarToArray(GameObject vehicleToAdd)
    {
        for (int i = 0; i <= vehicleInRace.Length; i++)
        {
            if (vehicleInRace[i] == null)
            {
                vehicleInRace[0] = vehicleToAdd;
                vehicleInRaceStats[0] = vehicleInRace[0].GetComponentInChildren<VehicleCurrentRaceStats>();
            }
        }
    }
}

If you have Pro, check the Profiler. My guess is that you’re seeing a performance drop due to garbage collector spikes, which I’m afraid, are a fact of life with the current GUI system: http://feedback.unity3d.com/forums/15792-unity/suggestions/1604963-gc-spikes-caused-by-ongui?ref=title

Yea I don’t have it at home just at school. I did narrow it down when I comment out the second line in on GUI it speeds up. There must be some way to speed it up

make a 3d gui with dials for numbers like old-school odometers? :slight_smile:

this particular gui is actually just a sidebar with each connected player having a box displaying the username, vehicle and lap so far. How do you make a 3d GUI?

You could use TextMesh

/Documentation/Components/class-TextMesh.html

for the names etc.

A 3D GUI has nothing to do with the GUI stuff from Unity. It’s just a bunch of objects you use instead of a 2d overlay. You could use a separate camera-layer for it.

hmm. ill have to look into it