- Home /
Other
ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint
Hello !
I got this error when I tried to handle a dialog score and an chat script together. They are in different scripts.
My chat dialog is always visible, and my dialog score is only visible when the user pushes the "tab" button. Each dialog works fine (I can see the score dialog if I press "tab" and if my chat dialog is inactive, and I can see my chat dialog if I don't press the "tab" button), but not together ...
I saw this question and I think I understand the explanation, but I don't know how to correct the problem. So if someone can help me, I'd be grateful :)
Here is the code for the chat dialog :
function OnGUI() {
if (loadedLevel != Application.loadedLevel)
{
loadedLevel = Application.loadedLevel;
if (loadedLevel == 4) windowChat = Rect(0.7*Screen.width, 0.8*Screen.height, 0.3*Screen.width, 0.2*Screen.height);
}
else if (gameOver) windowChat = Rect(0.5*Screen.width, 0, 0.5*Screen.width, Screen.height);
windowChat = GUI.Window (0, windowChat, GlobalChatWindow, "Chat");
}
function GlobalChatWindow (id : int) {
scrollPosition = GUILayout.BeginScrollView (scrollPosition);
for (var entry : ChatEntry in entries)
{
GUILayout.BeginHorizontal();
GUILayout.Label(entry.text);
GUILayout.FlexibleSpace ();
GUILayout.EndHorizontal();
GUILayout.Space(3);
}
// End the scrollview we began above.
GUILayout.EndScrollView ();
if (Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length > 0)
{
inputField = myNickname + ": " + inputField;
ApplyGlobalChatText(inputField, 1);
networkView.RPC("ApplyGlobalChatText", RPCMode.Others, inputField, 0);
inputField = "";
}
GUI.SetNextControlName("Chat input field");
inputField = GUILayout.TextField(inputField);
}
@RPC
function ApplyGlobalChatText (str : String, mine : int)
{
var entry = new ChatEntry();
entry.sender = "Not implemented";
entry.text = str;
entries.Add(entry);
if (entries.Count > 50)
entries.RemoveAt(0);
scrollPosition.y = 1000000;
}
It is quite the same code from the tutorials...
The problem happens when I try to display my score dialog too, here is the code :
function OnGUI() {
if (Input.GetKey(KeyCode.Tab)) enableScoreDlg = true;
if (Input.GetKeyUp(KeyCode.Tab)) enableScoreDlg = false;
}
function OnGUI() {
if (enableScoreDlg)
{
scoresDlg = GUI.Window(0, Rect (0.1*Screen.width, 0.1*Screen.height, 0.8*Screen.width, 0.8*Screen.height), ScoreWindow, "", scoreSkin.window);
}
}
EDIT : I finally managed to have my chat dialog and my scores dialog work, but not together ...
Now my script handling the chat is like :
function OnGUI() {
if (Event.current.type == EventType.Layout) windowChat = GUI.Window (0, windowChat, GlobalChatWindow, "Chat");
}
And my script handling my score dialog is like :
function OnGUI() {
if (enableScoreDlg)
{
scoresDlg = GUI.Window(0, Rect (0.1*Screen.width, 0.1*Screen.height, 0.8*Screen.width, 0.8*Screen.height), ScoreWindow, "", scoreSkin.window);
}
}
with enableScoreDlg true only when the user uses the "tab" key. My problem now is that there is never both the windows together. If the user presses "tab", the chat window disappears and my score dialog appears, when he releases it, my score dialog disappears and the chat reappears... What is wrong ?
This problem happens because you have some GUILayout container that is not closed correctly, maybe because it break out of a loop at the wrong point. If you want more help, you should post your code so we can see where it is wrong.
Follow this Question
Related Questions
Elements in draggable window do not remain fixed [SOLVED] 2 Answers
Add EditorUI elements when a button is pressed 0 Answers
Center GUI wondow or box in windowed mode 3 Answers
how to get Gui in OnGUI function to resize with the window? 1 Answer
Is it possible to have a spectrum analyzer display for each song in a playlist? 1 Answer