Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 TruffelsAndOranges · Jul 10, 2015 at 04:47 AM · crossfade

Text.CrossFadeAlpha not working?

I'm trying to fade in a UI component by using the following code:

 public float fadeTime = 1.0f;
 public Text textItemGUI; // Set through inspector.
 
 void Start() 
 {
     textItemGUI.CrossFadeAlpha(1.0f, fadeTime, true);
 }

Nothing happens! I'm logging the alpha in the update function and there I can see that the alpha is just kept 0.0 forever. What is wrong?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by ben-rasooli · May 01, 2017 at 01:37 AM

Graphic.CrossFadeAlpha() changes the alpha of the CanvasRenderer attached to the same gameObject, not the alpha of the Image.color. If you wanna start your image completely transparent and then fade it in, you need to set the alpha of its CanvasRenderer to zero like this imageComponent.canvasRenderer.SetAlpha(0);.Don't change the alpha of the Image.color.

Comment
Add comment · Show 2 · 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 JoeStrout · Sep 13, 2017 at 03:12 AM 0
Share

This should be the accepted answer. It is correct both in what you should do, and in the explanation as to why.

avatar image tmendez · Apr 11, 2019 at 09:32 PM 0
Share

This isn't working for a Text$$anonymous$$eshPro.CrossFadeAlpha(1f, 2f, false); It just never fades back in after setting the canvasRenderer's alpha to 0. Any ideas?

avatar image
2

Answer by Jeff_B · Jul 15, 2015 at 07:28 PM

Hellium fixed it for me. I added one line and now the following "fade in" line works! :

 (...)
     faderGraphic.canvasRenderer.SetAlpha(0.01);
     faderGraphic.CrossFadeAlpha(1.0, fadeSpeed, false);
     (...)




Comment
Add comment · Show 5 · 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 Rick74 · Feb 04, 2016 at 04:07 AM 0
Share

Thanks so much! This helped solved my same question!

avatar image Addyarb · Mar 17, 2016 at 01:52 PM 0
Share

This is great! Thanks to whomever posted that fix. I hardly use the canvasRenderer class for anything. For those learning to use this in C#, just be sure to add a lowercase "f" (SetAlpha(0.01f)).

I hope the docs will soon reflect that this value can not be zero to begin with - or else it just won't work.

I also hope that the class itself will eventually be updated to check if the alpha == 0, ins$$anonymous$$d of just not fading if so, with no errors.

avatar image Psigen · Aug 08, 2016 at 03:02 PM 0
Share

If anyone reading wonders why this solution with CrossFadeAlpha() works the way it does:

It is because when scripting in some cases, unity does not work with the default RGB values of 0 - 255. But rather a 0 - 1 float number representing the range of the value. (1f = 255).

You don't need to set the alpha in Awake(), but you do have to set the alpha as a starting point before using CrossFadeAlpha inside your function.

avatar image JoeStrout · Sep 13, 2017 at 03:12 AM 1
Share

This is a correct answer, but the other comments about it are incorrect. It works fine with an alpha of 0. And it has nothing to do with floats vs. integers. The confusion is that CrossFadeAlpha operates on the CanvasRenderer component's alpha value, not on the color of the Graphic you call it on.

avatar image halken · Feb 11, 2020 at 09:49 PM 0
Share

Thank you JoeStrout. Yes, that explains everything. The fix in my case was not changing the Image.color, but rather the Image.canvasRenderer.color when I initialize. Then CrosFadeAlpha works perfectly!

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

crossfade between skyboxes 1 Answer

Animation.isPlaying, but animation isn't playing 0 Answers

Unity 3.5 Animation : stop one layer 1 Answer

How to make CrossFade between 2 camera? 0 Answers

CrossFade with script? 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