Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by tkingsm74 · Apr 08 at 10:20 AM · 2d spritesstandalonefade

2D Image Sprite Not Fading In Standalone Build

In my recent 2D game, I wanted to fade certain scenes in and out. This is done by putting a black image overlay on top of everything in the scene and adjusting the transparency at appropriate times. Everything works perfectly in the editor. However, when I make a standalone build, the fade does not work properly. Instead, when fading the scene in (i.e. fading the black overlay from opaque to transparent), the overlay remains solid opaque black for the entire fade duration, then snaps to transparent at the end time at which it should have faded to transparent.

So far, while looking into the issue, I've seen people mention that this may be due to Unity needing you to specifically indicate you want to load certain textures in the standalone build through project settings. However, I can't seem to find how to do this for a 2D game with images.

Here is the inspector window for the relevant overlay: alt text

And here are some parts of the script that may be relevant:

 public class FadeInFromBlack : MonoBehaviour
 {
     private GameObject fadeFromBlackOverlay;
 
 
     private void Awake()
     {
         fadeFromBlackOverlay = this.gameObject;
     }
 
 
     // Start is called before the first frame update
     void Start()
     {
         //check to make sure we attached this to an image object
         if (fadeFromBlackOverlay.GetComponent<Image>() == null)
         {
             Debug.Log("No image component found on fadeFromBlackOverlay");
             return;
         }
         else
         {
             //set the black overlay to alpha 1 as we have it at alpha 0 right now; we left it at alpha 0 so that we can see the actual scene when we're working on it, but we need to start at full black overlay to "fade in"
             Color fadeFromBlackOverlayColor = fadeFromBlackOverlay.GetComponent<Image>().color;
             fadeFromBlackOverlayColor = new Color(fadeFromBlackOverlayColor.r, fadeFromBlackOverlayColor.g, fadeFromBlackOverlayColor.b, 1f);
             fadeFromBlackOverlay.GetComponent<Image>().color = fadeFromBlackOverlayColor;
         }
         //now we're ready to fade the scene in (i.e. fade the overlay out) 
         StartCoroutine(FadeIn());
     }
 
     IEnumerator FadeIn()
     {
         //check again just in case the image somehow disappeared 
         if (fadeFromBlackOverlay.GetComponent<Image>() == null)
         {
             Debug.Log("No image component found on fadeFromBlackOverlay");
             yield break;
         }
         //small pause
         yield return new WaitForSeconds(0.5f);
 
         //fade the overlay out (i.e. fade the scene in) over X seconds 
         fadeFromBlackOverlay.GetComponent<Image>().CrossFadeAlpha(0, 2.0f, false);
         //as that is happening, add a delay for the same time to prevent the rest of the coroutine from running 
         yield return new WaitForSeconds(2.0f);
 
         //small delay
         yield return null;
         //now we disable the overlay once it is transparent so that we can interact with the other things below it
         fadeFromBlackOverlay.SetActive(false);
     }

I'd like to emphasize here at the end that this issue only occurs in the standalone build; the script runs exactly as expected in the editor.

Thank you in advance for any suggestions you may have.

badinspector.png (38.9 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

140 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 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 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 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 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

How do I import a picture, from a standalone application, to be displayed on a texture of some kind? 1 Answer

How to record from standalone app built for windows10 automatically? 1 Answer

Cannot build standalone version with my custom DLL 0 Answers

How Would I Make A GUI Label Fade After A Certain Amount Of Time? 1 Answer

make buttons appear slowly 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