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
1
Question by MarwanMR1 · Jan 29, 2012 at 11:13 AM · colorguitextguistyle

NullReferenceException when using GUIStyle to change text color

I'm using OnGUI() to display text on the screen.

The Text is colored white, so I used GUIStyle to change the color to black as so

     GUIstyle.font.material.color = Color.black;


I get this error:

NullReferenceException: Object reference not set to an instance of an object

Test.Start () (at Assets/Scripts/s_Test.cs:15) Can anyone help me with this? Thanks in advance
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
2
Best Answer

Answer by dannyskim · Jan 29, 2012 at 10:53 PM

OnGUI elements don't utilize a traditional mesh based GUI system to display themselves. Therefor, there are no materials associated with them either.

If you were to utilize the older GUI Elements such as GUITexture, or GUIText, these accessors would still apply.

In order to access these variables, you can either access them through the Inspector if you expose your GUIStyle as a public variable instead of instantiating it at runtime, or you can access it through:

 GUIstyle.normal.textColor

When you browse through the GUIStyle in the inspector, you'll see that there are several different states that you can edit, such as normal, Hover, Active, Focused, etc. You can then change these colors accordingly by accessing them through their appropriate methods.

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 MarwanMR1 · Jan 29, 2012 at 11:48 PM 0
Share

Thanks, it worked perfectly. I don't have that error anymore.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I use a GUIStyle in a Custom Editor which is set within that Custom Editor? 1 Answer

GUILayout.SelectionGrid with GUIStyle ignores textColor 2 Answers

How do I construct an array of unique GUIStyles from the values in a single GUIStyle when apparently GUIStyles are passed by reference, not value. 1 Answer

How do I get the current alpha value of a material? 2 Answers

Material doesn't have a color property '_Color' 4 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