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
0
Question by Gilead7 · Jun 30, 2015 at 08:24 PM · c#guilayouttextfield

Head Scratcher for GUILayout.textfield

This makes no sense. I'm setting up forms for a 2d app to be stored in the asset database, but every time I use GUILayout.textfield the way I have used it in editor scripts many multiple times, I get an error.

 string bandName;
 
 inside a function:
 bandName=GUILayout.TextField("Item Name: " , bandName);


Here is the error: ArgumentNullException: Argument cannot be null. Parameter name: key System.Collections.Generic.Dictionary`2[System.String,UnityEngine.GUIStyle].TryGetValue (System.String key, UnityEngine.GUIStyle& value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:588) UnityEngine.GUISkin.FindStyle (System.String styleName) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUISkinBindings.gen.cs:275) UnityEngine.GUISkin.GetStyle (System.String styleName) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUISkinBindings.gen.cs:258) UnityEngine.GUIStyle.op_Implicit (System.String str) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUIStyleBindings.gen.cs:819) GUI.ChangeBandName () (at Assets/Scripts/GUI.cs:204) GUI.DetailView () (at Assets/Scripts/GUI.cs:107) GUI.OnGUI () (at Assets/Scripts/GUI.cs:66)

ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint Aborting UnityEngine.GUILayoutGroup.GetNext () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUILayoutUtilityBindings.gen.cs:511) UnityEngine.GUILayoutUtility.BeginLayoutGroup (UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options, System.Type LayoutType) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUILayoutUtilityBindings.gen.cs:208) UnityEngine.GUILayout.BeginHorizontal (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUILayoutBindings.gen.cs:235) UnityEngine.GUILayout.BeginHorizontal (UnityEngine.GUILayoutOption[] options) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GUILayoutBindings.gen.cs:227) GUI.OnGUI () (at Assets/Scripts/GUI.cs:64)

Line 64: GUILayout.BeginHorizontal(); in the OnGUI function Three lines later, I close it. GUILayout.EndHorizontal();

If I comment out the textfield line, it works. Anyone make head or tales of this? Thanks!

Comment
Add comment · Show 1
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 Mike-Geig ♦♦ · Jul 01, 2015 at 01:49 PM 0
Share

Initialize your string as something.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jessespike · Jun 30, 2015 at 08:50 PM

The string is null as described in the cryptic error. GUILayout might need to be EditorGUILayout as well.

  string bandName = "";

  bandName = EditorGUILayout.TextField("Item Name: " , bandName);

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 Gilead7 · Jun 30, 2015 at 11:18 PM 0
Share

Thanks Jessespike- if this is not going to be used in a custom editor/inspector, what should be used?

avatar image
1

Answer by Bunny83 · Jul 01, 2015 at 12:03 AM

Well, just take a look at the description of the TextField. A Text field doesn't have a caption / label as it's editor version has. A GUILayout.TextField is just a textfield. Your problem is that your first string is used as "text" and the second one as GUIStyle as there is an implicit cast from string to GUIStyle. Since thestring you pass seems to be null / not initialized it throws an error when it tries to resolve the GUIStyle.

If you need a label for your text field you have to use a seperate GUILayout.Label.

ps: The EditorGUI / EditorGUILayout class is only available in the editor. It's just an extension of the runtime classes GUI and GUILayout. In the editor you can use whatever function suits your need. However runtime scripts can only use GUI and GUILayout

Comment
Add comment · Show 2 · 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 Gilead7 · Jul 01, 2015 at 05:10 PM 0
Share

Thanks Bunny! Guess it's back to the classic rects. Was hoping to get away from that.

avatar image Bunny83 · Jul 01, 2015 at 09:57 PM 0
Share

@Gilead7: Huh? Why? You can still use GUILayout. If you want something like the editor version do something like this:

 public static string LabeledTextField(string aLabel, string aText)
 {
     GUILayout.BeginHorizontal();
     GUILayout.Label("Your label:", GUILayout.$$anonymous$$axWidth(100));
     aText = GUILayout.TextField(aText);
     GUILayout.EndHorizontal();
     return aText;
 }

This is just an example and it's not very customizable in it's current form. However you can make the style a parameter as well, you just need a lot overloads unless you always provide all needed info.

$$anonymous$$eep in $$anonymous$$d that you can create even your own cusom GUI components. If you're interested in that kind of development you should get ILSpy (if you don't have it already) and take a look at how the TextField is implemented in the EditorGUILayout namespace (UnityEditor.dll) and the GUILayout namespace (Unityengine.dll). Just as reference my GUI crash course ^^.

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

23 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

TextField does not show up 2 Answers

Very simple - Appending a space to GUILayout.Label (C#) 2 Answers

How to fix ArgumentException? 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