• 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 /
This question was closed Aug 09, 2014 at 08:15 PM by Graham-Dunnett for the following reason:

Duplicate Question

avatar image
0
Question by fddefdef · Aug 09, 2014 at 08:13 PM · textscenenullreferenceexceptionnull reference exception

Text field issue switching from scene to another scene

Hi Guys,

i have created two scenes in my game. One is called "StartScene" and one "CreatePlayerScene". There is a text field in the last one which works perfectly if i start the scene directly from the editor. But if i switch from StartScene to CreatePlayerScene by pressing space the text field stop working and i get this error:

NullReferenceException: Object reference not set to an instance of an object UnityEngine.TextEditor.ClampPos () (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/TextEditor.cs:1251) UnityEngine.GUI.DoTextField (Rect position, Int32 id, UnityEngine.GUIContent content, Boolean multiline, Int32 maxLength, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUI.cs:550) UnityEngine.GUI.TextField (Rect position, System.String text) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUI.cs:440) MenuScript.OnGUI () (at Assets/Scripts/MenuScript.cs:41)

Why?

Here's the part of the code where i use the text field.

     void OnGUI ()
     {
         GUI.skin = myGuiSkin;
 
         if(!showTextField)
         {
             if(GUI.Button (new Rect(Screen.width/2f - Screen.width*0.1f, Screen.height/2f, 500, 100), "New Game"))
             {
                 showTextField = true;
             }
         }
 
         if(showTextField)
         {
             playerName = GUI.TextField(new Rect(Screen.width/2f - Screen.width*0.1f, Screen.height/2f, 500, 50), playerName);
             PlayerPrefs.SetString("playerName", playerName);
         }
 
     }
Comment
Comments Locked · 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 Graham-Dunnett ♦♦ · Aug 09, 2014 at 08:14 PM 0
Share

There are around 700 previously asked questions about null reference exceptions.

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Change scene using text UI ? help 1 Answer

How do I reference something from another scene? 0 Answers

Null Reference Exception, what is it and why do I get it? 1 Answer

NullReferenceException on empty project because of ScriptCompilerBase 0 Answers

Problems with Classes...i think 1 Answer


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