Search Unity

Trying to display combat log but windowID not resetting on level load?

Discussion in 'Scripting' started by Jeepster, Apr 7, 2021.

  1. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    Hi,

    I have a combat log that displays who killed whom but it only works in the first level of a tournament. On second level load and onwards the log is not displayed. Here's the code:

    This function is called OnGUI with *
    Code (CSharp):
    1.    
    2. void CombatWindowFunction(int windowID )
    3.     {
    4.         GUILayout.Label(combatLog, myStyle);
    5.         Debug.Log("We should see the combat log");
    6.  
    7.     }
    * this line (inside OnGUI) :
    windowRect = GUI.Window(4, windowRect, CombatWindowFunction, "Death Log");

    But I know the issues stems from the "int windowID" because my Debug.Log isn't called on second level load whilst another debug inside OnGUI is.
    So since "int windowID" should be unique according to the API, should I reset it on level load or how do I do this?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Well...first, why are you using OnGui instead of the new UI?

    Second...we don't have enough info. Showing that single method tells us nothing about what windowID is.
     
    Joe-Censored likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    How can windowID be the problem when you never use windowID? Legacy GUI stuff isn't really recommended for in game use anymore outside of hidden dev debug displays. Though I thought they finally ripped all this stuff out, but I'm probably wrong.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,729
    I think they just removed the "GUI Layer" object they used to stick beside the Camera. It's no longer needed apparently.

    And just what API might this be?
     
    Joe-Censored likes this.
  5. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    https://docs.unity3d.com/ScriptReference/GUI.Window.html
    I see it's not the same ID now. Still don't know what causes the issue or how to fix it though
     
  6. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    I am using it, and you are wrong ;-) the line windowRect = GUI.Window(4, windowRect, CombatWindowFunction, "Death Log"); uses it because it's a GUI.Window
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,729
    This Legacy GUI API stopped being used in 2014 or so for games, except for Editor scripts, as Uncle Joe pointed out.

    You can persist and perhaps get it working (if it still is functional; I don't know!), but know that as Joe points out, it will someday stop working in Unity.

    Instead, look into the new UI system (now eight years old so not so new anymore!), which lets you visually build your interface and script against it. There's a LOT of tutorials out there about it and it has become a very well-understood way to make modern user interfaces.
     
    Last edited: Apr 8, 2021
    Joe-Censored likes this.
  8. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    I'm forced to used unity 2017 because of assets depending on that version that would mess up my project if I update, so while I appreciate the age of the this Legacy GUI API, its working in the first level, I'm guessing there's a reasonable explanation as to why it doesn't in the subsequent ones, maybe not. Its sole purpose is to display one line of text showing who killed who. But I guess if you or anybody else also have no idea why it only works in the first level load I'll have to start over...
     
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,729
    Jeepster and Joe-Censored like this.