- Home /
GUI.Window only shows for one frame under all circumstances
Okay, this is really starting to annoy me as I've tried to fix it for over a week now and the internet doesn't help at all because people keep asking this question saying that they put the window call in a GUI.Button statement.
GUI.Window will NOT render for me even if I put it under the OnGUI function with nothing else in there.
I've tried GUI.Window and GUI.ModalWindow (which is what I'm aiming to do).
Please help me fix this, I've also tried putting it in multiple different scripts and it will not work, here's something similar to what I'm doing:
function OnGUI(){
GUI.Window(0, Rect(0, 0, 1920, 950), StupidAssWindow, "The non-renderer");
}
function StupidAssWindow(id : int){
print("I don't ever print to the console");
}
That's not the exact code I use but I only have different names set, this won't work. Please help me.
And if you can find the fix in C# I can understand C# nearly as well as JS so I can translate it fine.
I just moved this question from Help Room to Default to see if that will help, I still can't fix this issue.
Answer by Wolfrik_Creations · May 27, 2016 at 04:12 PM
After over two weeks I finally figured it out! I feel like such a dumbass now,
Children, DO NOT PUT useGUILayout = false; IN YOUR GUI SCRIPT IF YOU WANT WINDOWS!
I don't even know what that statement does but it was in my script and that's what caused it to not work. Thank you everyone for your help, without you I wouldn't have looked at that line of code.
Answer by Bunny83 · May 26, 2016 at 11:22 PM
I just tried your exact example code and it works as expected. I get an empty window that covers the whole screen and each frame i get two times the line "I don't ever print to the console" ...
I could have told that without even trying but i just want to be sure as i never use UnityScript.
So if it doesn't work for you, there must be something else going on. Are you sure your script is enabled and doesn't get disabled be some other script? Same for the gameobject it's attached to. Maybe you disable or destroy the gameobject somewhere?
Try adding:
function Update() {
print("Update, yeah");
}
and see if that prints. If not your script is most likely not enabled or not there anymore.
edit
As i already wrote in the comment below (which got burried under several other comments) the reason why your GUI.Window doesn't work is because you disabled the Layout event.
See the documentation for more details:
if MonoBehaviour.useGUILayout is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.
The script I'm using is over 2,000 lines of code and it's really important so it's never disabled, in fact it is attached to my player.
Well, it does work Are you sure that's the only window you try to display? $$anonymous$$eep in $$anonymous$$d that every window need a unique window ID. You can't have two windows with the same ID.
Well you disabled the Layout event, that's the reason why the Window doesn't work. GUI.Window needs the Layout event. Just read the documentation:
[...] if $$anonymous$$onoBehaviour.useGUILayout is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.
That matrix shouldn't cause that much problems as long as your native_width /_height have reasonable values.
well if u have one script that is 2000 lines long ... wow. I have a 500 script RPG project atm, and even CombatReferee.cs (the longest script) is only 500 lines. I would srsly suggest for your own peace of $$anonymous$$d and for readability that you attempt to break up that monster. It might make finding small problems like this easier.
I$$anonymous$$HO its always good to take a break from progress with the project to sit back, collect on how far you have come and try to tidy up. Good luck with your project!
I do that, every few weeks I build the game and debug the multiplayer with my friends and we build a huge house in-game and then blow it up and watch the glory.
I have multiple scripts nearly as long as 2k lines, I keep them in one script for effeciency and performance, the game looks really good and runs amazingly even on shitty laptops and such, zombies and structures have no performance affect due to my way of coding and I rarely ever use the stupid Update or FixedUpdate functions as they highly drain performance, use true loops ins$$anonymous$$d.
And, thank you!
Your answer
Follow this Question
Related Questions
using GUI scrollView for multiple onGUI functions 0 Answers
GUI.Window Problem Option Menu 1 Answer
GUI opacity. 1 Answer
Open window GUI when I touch the object in iOs (javascript) 1 Answer
Setting Scroll View Width GUILayout 1 Answer