Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
4
Question by TheMorten · May 20, 2010 at 09:45 AM · guinetworkrpcexceptionargumentexception

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

Hey,

I've created a script that enters a text string, created in another script, into a chat box window with scrollview.

I get the following error message, even though the program seems to work like it should:


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

UnityEngine.GUILayoutGroup.GetNext () UnityEngine.GUILayoutUtility.BeginLayoutGroup (UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options, System.Type LayoutType) [0x00000] UnityEngine.GUILayout.BeginHorizontal (UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) [0x00000] UnityEngine.GUILayout.BeginHorizontal (UnityEngine.GUILayoutOption[] options) [0x00000] Chat.GlobalChatWindow (Int32 id) (at Assets\Example1\Chat.js:250) UnityEngine.GUI+_Window.Do () UnityEngine.GUI.BeginWindows (UnityEngine.Event e, Int32 skinMode, UnityEngine.IDList idlist, Int32 editorWindowInstanceID)


The only thing that does not work is that the scroll window does not automatically scroll down to show the last entry (but it does scroll to show the second-to-last entry).

I've used the M2H Networking Project, the companion project to the pdf "Unity networking; the Zero to Hero guide". In it, I've added my own RPC script:

@RPC
function RollCall(name : String, total : String, dice : String) {
    addGameChatMessage(name+" rolls "+total+", on "+dice);
}

The addGameChatMessage function, for reference:

function addGameChatMessage(str : String){ ApplyGlobalChatText("", str); if(Network.connections.length>0){ networkView.RPC("ApplyGlobalChatText", RPCMode.Others, "", str); } }

The ApplyGlobalChatText function:

 @RPC
 function ApplyGlobalChatText (name : String, msg : String)
 {
     var entry = new ChatEntry();
     entry.name = name;
     entry.text = msg;

     chatEntries.Add(entry);

     //Remove old entries
     if (chatEntries.Count > 300){
         chatEntries.RemoveAt(0);
     }

     scrollPosition.y = 1000000; 
 }

The RollCall function is called inside the function of a window, called GlobalChatWindow. The script basically checks to see if anything is stored in MouseInformer.dList and if there is, this data is cleared and a chat message is generated. In my own script the MouseInformer.dList contents are gathered into strings and send to the RollCall function, but since this has nothing to do with the exception, I've removed the code responsible for that:

function GlobalChatWindow (id : int) {

 GUILayout.BeginVertical();
 GUILayout.Space(5);
 GUILayout.EndVertical();

 // Begin a scroll view. All rects are calculated automatically - 
 // it will use up any available screen space and make sure contents flow correctly.
 // This is kept small with the last two parameters to force scrollbars to appear.
 scrollPosition = GUILayout.BeginScrollView (scrollPosition);

 for (var entry : ChatEntry in chatEntries)
 {
     GUILayout.BeginHorizontal(); //UNITY SAYS THIS IS WHERE THE EXCEPTION ORIGINATES
     if(entry.name==""){//Game message
         GUILayout.Label (entry.text);
     }else{
         GUILayout.Label (entry.name+": "+entry.text);
     }
     GUILayout.EndHorizontal();
     GUILayout.Space(-5);

 }
 // End the scrollview we began above.
 GUILayout.EndScrollView ();

 var mouseInformer : MouseInformer = GetComponent("MouseInformer");
 if (checkWindow.Contains(Input.mousePosition) && Input.GetMouseButtonDown(0) && mouseInformer.dList.length > 0) {

     mouseInformer.ClearAll();
     //networkView.RPC("RollCall", RPCMode.All, playerName, outputTotal+"", diceTypeString);
     networkView.RPC("RollCall", RPCMode.All, playerName, "Result", "Many dice");

 }

 if (Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length > 0)
 {
     HitEnter(inputField);
 }
 GUI.SetNextControlName("Chat input field");
 inputField = GUILayout.TextField(inputField);

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
12
Best Answer

Answer by Ray-Pendergraph · May 20, 2010 at 12:46 PM

I believe the problem could be in your for loop over chatEntries. There are two passes to the OnGUI thread (they are called "events" in Unity), the layout event runs through and basically does roll call and layout planning on the GUI components and the repaint event draws the components to the screen. If the components change between these two GUI events, the layout manager gets confused and produces this message. The contents of your chat entries is externally controlled (from the OnGUI thread's perspective) and may be changing the contents of that collection between the events. This is forbidden.

Not absolutely sure that field is your problem but that's where I would start. That message is always produced in a circumstance like this. I have gotten around this before by creating a copy of the externally controlled collection in the layout pass (i.e., Event.current.type == EventType.Layout).

Comment
Add comment · Show 1 · Share
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 Molix · May 20, 2010 at 01:45 PM 0
Share

An alternative to copying the entire collection would be to queue up the new messages that arrive mid-frame and add them all at once. e.g. in ApplyGlobalChat, add them to a "newChat", and then in Update, add whatever is in newChat to chatEntries, and clear newChat.

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

1 Person is following this question.

avatar image

Related Questions

Network Instaniate,Lag,Bullet Prefab 1 Answer

ArgumentException: Getting control 1's position in a group with only 1 controls when doing Repaint 2 Answers

send complex objects over RPC 4 Answers

Sending bulk data via rpc 1 Answer

Buffered RPCs Only Sent To One New Client 0 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