Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Restoring GUI.matrix

Discussion in 'Immediate Mode GUI (IMGUI)' started by JohnGalt, Apr 12, 2008.

  1. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    When you change GUI.matrix you have to restore it afterwards, right? It doesn't get automatically restored at the end of the OnGUI of this script, so the next OnGUI of other script finds it with the default value, right?

    And what about when you use GUIUtility.RotateAroundPivot? Do u have to store it and restore afterwards?

    Thanks!!
     
  2. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    I'm doing that all the time... to be honest, I haven't checked what happens if you don't do it, though... but since it's just two trivial lines of code, I didn't worry too much about it. Simply put the matrix into a temp variable when I begin, and put it back when I'm done...

    Sunny regards,
    Jashan
     
  3. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Try toggling the "do matrix" var in the inspector on this script to test it:
    Code (csharp):
    1.  
    2. var doMatrix = true;
    3. function OnGUI () {
    4.     if (doMatrix)
    5.         GUIUtility.ScaleAroundPivot (Vector2 (1.5, 1.5), Vector2 (0,0));
    6.     GUI.Button (Rect (0,0,100,20), "Hello");
    7. }
    8.  
    GUI.Matrix gets reset before calling a new OnGUI, so you don't need to load the identity matrix before exiting.
     
  4. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    Very good to know, in the end this little things may accumulate and impact on performance.

    Does it happen the same with GUI.color, etc?


    Thanks