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 Eowyn27 · Feb 14, 2014 at 12:58 AM · guigameobjectbuttoncolorrenderer.material.color

Changing gameobject material color makes object disappear from view. How can I fix this?

I have this bit of code that says:

     bool bt1 = false; 
 public GameObject Stripe1; 


 public bool setMeOnly() {
     
     bt1 = bt2 = bt3 = bt4 = bt5 = bt6 =bt7 = false;
     return true;
     
 } 


 void OnGUI() {
             bt1=GUI.Toggle(new Rect(300, 85, 100, 30), bt1, "");
             if(bt1) bt1=setMeOnly();



             if (bt1 == true) {
                 
             
                 
                 Stripe1.renderer.material.color = Color.red;
                 Stripe1.renderer.enabled = true;
                 
             }

Howver, instead of rendering the stripe1 color to red, the game object stripe 1 disappears from the scene (although it's listed on the left panel in the hierarchy).

I'm not sure why, there are no errors in the log.

Although when I manually change it to red when the game is in session (scene is played), I get this error that says all the duplicate objects to red:

 rc.right != m_GfxWindow->GetWidth() || rc.bottom != m_GfxWindow->GetHeight()

 GUI Window tries to begin rendering while something else has not finished rendering! Either you have a recursive OnGUI rendering, or previous OnGUI did not clean up properly.

Here's a bit of background on what I'm trying to do. I have duplicate objects called "Cube". They all contain the same material, color but positioned different on the scene. When I click on a toggle button next to the game object cube (stripe), the stripe should turn from default gray to red if the toggle button = true. However, instead of turning red, the object disappears from the scene. That is stranger is that when I click on Cube "Stripe1" on the hierarchy, I can see that it says "Gray (instance) and the color is now changed to red" even though the object disappeared.... This is strange since the Mesh Renderer is checked and the cube is checked off as well in the inspector.

Comment
Add comment · Show 2
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 Eowyn27 · Mar 06, 2014 at 05:56 PM 0
Share

Any ideas anyone?

avatar image perchik · Mar 06, 2014 at 06:00 PM 0
Share

When it runs, and you can see it in the inspector, what does it say the material color is?

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by Leckofunny · Apr 16, 2014 at 10:54 PM

Its a problem of transparency. For some reason Color.red has a transparency value of a = 0 i.e. completely transparent, which is why your stripe1 disappears. You can either set the Color by creating a new one: new Color(someRedValue,someGreenValue,someBlueValue,1f) or if you have a variable for the desired color (for example myColor) then you can just set the transparency value to 1: myColor.a = 1f;

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

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

20 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

Related Questions

Bullet Prefab not instantiating 1 Answer

guiTexture color half alpha White? 1 Answer

Char select / GUI button question. 3 Answers

How to have correct color on imGUI Buttons (as dynamic textures) avoiding multiply effect ? 1 Answer

How to change text color on hover in new GUI? 10 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