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 TheQuantumGamer · Jun 25, 2015 at 09:51 PM · materialcoloralphafontcolour

Text not reverting back to original properties after gameplay

I have no idea why this is happening but for some reason, after changing the alpha value to zero of the text material colour during gameplay, the alpha value does not revert back after I click the stop button. The alpha value remains 0. Here is the code i am doing:

      IEnumerator Fade(){
         for (float alpha = 1; alpha > 0; alpha -= (Time.deltaTime * fadeSpeed)) {
         Color color = gameObject.GetComponent<Text>().material.color;
         color.a = alpha;
         gameObject.GetComponent<Text>().material.color = color;
         yield return null;

     }
 }


Any suggestions on why this is happening?

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
1
Best Answer

Answer by zach-r-d · Jun 25, 2015 at 09:59 PM

This is probably because, unlike MeshRenderer.material, Text.material does not make a copy of the material before editing it. So if the material of the Text component is an asset, changing its properties in play mode will edit the asset directly rather than a copy that will cease to exist when play mode is exited.

One quick solution is to manually make a copy of the material when in the editor; try sticking this in the Start() method of the same script:

 #if UNITY_EDITOR
 GetComponent<Text>().material = new Material(GetComponent<Text>().material);
 #endif
Comment
Add comment · Show 3 · 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 TheQuantumGamer · Jun 26, 2015 at 03:26 PM 1
Share

Thanks, I was wondering for quite some time of why this was happening. Btw can you think of any particular reason, why text material doesn't make a copy before editing?

avatar image zach-r-d · Jun 26, 2015 at 08:22 PM 0
Share

Probably to prevent leaks. When cloning a $$anonymous$$aterial, it is the script's responsibility to Destroy() it. See the note in the documentation for Renderer.material.

avatar image TheQuantumGamer · Jun 27, 2015 at 01:00 PM 0
Share

Thanks again for the extra info

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Changing two different objects renderer colour 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Cannot change material colour 2 Answers

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

How to change font 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