Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SteenPetersen · Aug 17, 2017 at 02:37 PM · guiguilayoutargumentexception

ArgumentException: getting control 2's position in a group with only ... Gui.Layout issue.

I am building a chat program for my game and everything is working fine but I am getting this error and I can seem to remove it. here is my script:

     private void OnGUI()
     {
         if (!Client.isConnected)
             return;
 
         Event e = Event.current;
         if (e.type == EventType.keyDown && e.keyCode == KeyCode.Return)
         {
             if (GUI.GetNameOfFocusedControl() == "chat_input")  // if you are focusing on the text field
             {
                 SendMessage();
                 currentMessage = "";
                 Invoke("ScrollToBottom", 0.15f);
                 GUI.FocusControl("");                           // remove focus from textfield
             }
             else if (GUI.GetNameOfFocusedControl() != "chat_input")  // if you are NOT focusing on the text field
             {
                 GUI.FocusControl("chat_input");                 //  focus on the textfield
             }
         }
 
         if (chatHistory.Count > 50)
         {
             chatHistory.RemoveAt(0);
         }
 
         LoadGui();
     }
 
     private void LoadGui()
     {
         GUILayout.BeginArea(new Rect(0, Screen.height - 255, 450, 222));
 
         scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(450), GUILayout.Height(222));
 
         foreach (var chatMessage in chatHistory)
         {
             if (chatMessage.StartsWith("ThisIsATell"))
             {
                 string msg = BuildMessage(chatMessage);
 
                 GUI.skin = tellSkin;
                 GUILayout.Label(msg, GUILayout.MaxWidth(450));
             }
 
             else if (chatMessage.StartsWith("ThisIsAServerMessage"))
             {
                 string msg = BuildMessage(chatMessage);
 
                 GUI.skin = server_messages_skin;
                 GUILayout.Label(msg, GUILayout.MaxWidth(450));
             }
 
             else if (chatMessage.StartsWith("ThisIsANormalMessage"))
             {
                 string msg = BuildMessage(chatMessage);
 
                 GUI.skin = normalSkin;
                 GUILayout.Label(msg, GUILayout.MaxWidth(450));  // this is the line Unity complains about
             }
         }
 
         GUILayout.EndScrollView();
         GUILayout.EndArea();
 
         GUI.SetNextControlName("chat_input");
         currentMessage = GUI.TextField(new Rect(0, Screen.height - 25, 450, 25), currentMessage);
         currentMessage = Regex.Replace(currentMessage, @"[^a-zA-Z0-9/!?-_ ]", "");
     }

Hope someone knows what wrong here. any help is appreciated.

thanks.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SteenPetersen · Aug 19, 2017 at 08:22 AM 0
Share

Still a bit stumped by this, I have learned that it has something to do with changing layout elements during the keydown event

avatar image AdmiralThrawn · Aug 19, 2017 at 08:38 AM 0
Share

What is the full exception you get? Can you drop that here for us? Another thing I noticed while going through your code: 1. In your else branch you don't need to check for GUI.GetNameOfFocusedControl() != "chat_input" if your first condition already covers GUI.GetNameOfFocusedControl() == "chat_input". 2. I'm not 100% sure if C# is perfor$$anonymous$$g equally well with comparing string objects by using "==" operator, but I recommend you to use equals(string yourString), so it would be GUI.GetNameOfFocusedControl().equals("chat_input").

avatar image SteenPetersen AdmiralThrawn · Aug 19, 2017 at 08:41 AM 0
Share

ArgumentException: Getting control 2's position in a group with only 2 controls when doing keyDown Aborting.

avatar image SteenPetersen SteenPetersen · Aug 19, 2017 at 08:43 AM 0
Share

@AdmiralThrawn So when I activate the keydown event I get the execption. I cant see what it is I am changing in that call. im a bit confused as to why something is getting changed between the 2 calls.

I read this thread thoroughly still cant find my issue:

http://answers.unity3d.com/questions/400454/argumentexception-getting-control-0s-position-in-a-1.html

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

111 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to disable horizontal scrollbar in GUILayout scroll view? 3 Answers

Additional parameters for GUILayout.Label 1 Answer

Using treeview OnGUI with GUIlayout 0 Answers

GUI.FocusControl() and TextFields - Prevent selection 1 Answer

button with content in multiple colors 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges