• 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 Nov 09, 2016 at 06:53 PM by tanoshimi for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by akuseix · Nov 09, 2016 at 08:31 AM · spriterenderercolor change

Why is SpriteRenderer color working in Inspector but not Game View at runtime?

I asked this over on stackoverflow but I figured I'd ask it here as well.

I have a GameObject with a SpriteRenderer and its default color is set to white. At runtime I'm setting the color to Color.gray and for some reason it is not updating at runtime to the new gray tint. I have confirmed that the objects in my script are correct because the sprite completely disappears if I set enabled to false and if I have the object selected in the editor and play, the color changes in the Inspector but does not update in the Game View.

This is my simple script

 public class GameManager : MonoBehaviour
 {
     public SpriteRenderer Player1;
     public SpriteRenderer Player2;
 
     public void SetTurn(bool isPlayer1)
     {
         this.Player1.color = Color.gray;
         this.Player2.color = Color.gray;
 
         if (isPlayer1)
             this.Player1.color = Color.white;
         else
             this.Player2.color = Color.white;
     }
 }

SetTurn is being called from a different script in its Update on a mouse click; I have verified that the function is actually running. I've also tried simplifying this to:

 public class GameManager : MonoBehaviour
 {
     public SpriteRenderer Player1;
     public SpriteRenderer Player2;
 
     private void Update()
     {
         this.Player1.color = Color.red;
     }
 }

That doesn't even work. There are no warnings and no errors in the console either. I've tried rebooting, rebuilding, quitting and restarting, running on a different machine and running on a completely different platform... nothing works.

Any idea what I'm doing wrong? Again, the color changes in the Inspector at runtime but does not in the Game View. Also, if I change the color manually in the Inspector at runtime the Game View does change color, it just refuses to do it from the script.

I've also tried using Color32 just to cover my bases and that doesn't work, as I expected it wouldn't.

UPDATE

I completely removed the script and made a new script that I attached directly to the GameObject itself and that doesn't even work.

 public class test : MonoBehaviour
 {
     private SpriteRenderer m_Renderer;
 
     void Start()
     {
         this.m_Renderer = this.GetComponent<SpriteRenderer>();
     }
 
     void Update()
     {
         this.m_Renderer.color = Color.black;
         Debug.Log("COLOR BLACK");
     }
 }

The console displays "COLOR BLACK" so I know the Update is being called but still no color change in Game View or Scene View but it does change in the Inspector

UPDATE 2

I narrowed it down but still haven't solved it. I'm using the 2d experimental build 5.5.0a6. I installed the current stable version 5.4.2f2 and the problem does not exist! So, the problem has something to do with the SpriteRenderer in version 5.5.0a6. I'm trying to find out what the issue is, and I hope this gets fixed soon.

UPDATE 3 Here is a link to 2 simple projects that illustrate the issue. One for version 5.5.0a6 which DOES contain the issue and the exact same project for version 5.5.2f2 which DOES NOT contain the issue.

Sample Projects

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 aditya007 · Nov 09, 2016 at 08:45 AM 0
Share

In SetTurn(bool isPlayer1) function, first you're changing the sprite colors to Gray and then acc to the condition, you're resetting one of the color to White again. Do both of the sprite renderers have white color or only the other one?. And also, you have 2 SpriteRenderer and maybe looking at only one of them?

Show more comments

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Nov 09, 2016 at 06:53 PM

The fact that you're only experiencing this in an experimental pre-alpha build of Unity means you should probably report it to the testing group on the appropriate forum rather than here: https://forum.unity3d.com/forums/2d-experimental-preview.104/

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 akuseix · Nov 09, 2016 at 07:28 PM 0
Share

I did already and when I posted it here initially I didn't realize it was an issue only affecting the preview build and since have tested both versions.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Erase certain color from sprite 0 Answers

SpriteRender.color not changing the color 1 Answer

Changing color on pixel art 1 Answer

Vector Graphics Package Change sprite color 4 Answers

Array of colors not working, all sprites turn white. 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