• 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
Question by El-Deiablo · Jul 07, 2016 at 04:12 AM · canvasscene-loadingscene-switchingscene-changefadeout

Fadeout Issue

I am almost done with my scenefader. The fadein works properly, but the fadeout lags terribly. What could be casuing this? I have a video showing the problem and the animator in action - https://youtu.be/q9_cDFnENi4.

Change Scene Manager Code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine .SceneManagement ;
 using UnityEngine .UI;
 
 public class ChangeSceneManager : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
 
     }
 
     // Update is called once per frame
     void Update () {
 
     }

//Button Functions

     public void MainMenu(){
 
         SceneFader.instance.FadeIn("Title Menu");
 
     }
 
     public void HowToPlay(){
 
         SceneFader.instance.FadeIn ("How To Play Scene");
   
     }
 
     public void Play(){
 
         SceneFader.instance.FadeIn ("Gameplay");
 
 }
 
 }  

Scene Fader Code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 
 public class SceneFader : MonoBehaviour {
 
     public static SceneFader instance;
 
     [SerializeField]
     private GameObject fadeCanvas;
 
     [SerializeField]
     private Animator fadeAnim;
 
     void Awake(){
 
         MakeASingleInstance ();
 
     }
 
     void MakeASingleInstance(){
 
         if (instance != null) {
 
             Destroy (gameObject);
 
         } else {
 
             instance = this;
             DontDestroyOnLoad (gameObject);
 
         }
 
     }
 
     IEnumerator FadeInAnimate (string levelName){
 
         fadeCanvas.SetActive (true);
         fadeAnim.Play ("FadeIn");
         yield return StartCoroutine(MyCoroutine.WaitForRealSecond(0.5f));
         SceneManager.LoadScene (levelName);
         FadeOut ();
 
     }
         
     IEnumerator FadeOutAnimate(){
 
         fadeAnim.Play ("FadeOut");
         yield return new WaitForSeconds (1f);
         fadeCanvas.SetActive (false);
 
     }
 
     public void FadeIn(string levelName){
 
         StartCoroutine (FadeInAnimate(levelName));
 
     }
 
     public void FadeOut(){
 
         StartCoroutine (FadeOutAnimate());
 
     }
 }

My Coroutine Code:

 using UnityEngine;
 using System.Collections;
 
 public static class MyCoroutine {
 
     public static IEnumerator WaitForRealSecond(float time){
 
         float start = Time.realtimeSinceStartup;
 
         while (Time.realtimeSinceStartup < (start + time)) {
 
             yield return null;
 
         }
 
     }
 
 }





Comment

People who like this

0 Show 10
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 Eugenius · Jul 08, 2016 at 07:46 AM 0
Share

Did you try calling your "WaitForRealSeconds" code in the fadeout as well?

Right now I see you're calling it for the fade in but calling WaitForSeconds in fade out. Also, WaitForRealSeconds seems to be fading faster (since you're calling the code via 0.5f) while WaitForSeconds will fade slower (since you're telling it to run every 1 second).

Hope this helps solve the issue.

avatar image El-Deiablo Eugenius · Jul 08, 2016 at 08:16 AM 0
Share

Thanks for the input, but this unfortunately did not work.

avatar image RakshithAnand · Jul 08, 2016 at 08:21 AM 0
Share

I assume you are animating the canvas group's alpha value. Instead of animating it, you can just use a tweener(ex: Lean Tween ) and tween the alpha in certain time.

avatar image El-Deiablo RakshithAnand · Jul 08, 2016 at 08:41 AM 0
Share

Would I need to make an entirely different code? I tried messing around with the crossfade alpha option in a seperate code, but didn't get it to work. Would it be possible to implement your solution into my current code?

avatar image RakshithAnand El-Deiablo · Jul 08, 2016 at 09:23 AM 0
Share

Assuming you use "LeanTween" you can do this on your canvas group's (cg) alpha. Just one line of code.

 LeanTween.value(gameObject, (val)=> { cg.alpha = val; }, cg.alpha, 0, 1);

Above you are tweening the value from current cg.alpha to 0 in time of 1 second and for every value update you are assigning the alpha value (which you can see in the update delegate)

Show more comments
Show more comments
avatar image El-Deiablo RakshithAnand · Jul 08, 2016 at 06:25 PM 0
Share

I now have leantween and updated my code with your suggestions, but have not been able to get it to work. I also attached some pictures of my inspector and hierarchy.

Here's my updated code:

SceneFader:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 
 public class SceneFader1 : MonoBehaviour {
 
     public static SceneFader1 instance;
 
     [SerializeField]
     private CanvasGroup cg;
 
     void Awake(){
 
         Time.timeScale = 1f;
         MakeASingleInstance ();
 
     }
 
     void MakeASingleInstance(){
 
         if (instance != null) {
 
             Destroy (gameObject);
 
         } else {
 
             instance = this;
             DontDestroyOnLoad (gameObject);
 
         }
 
     }
         
 
     public void FadeIn(string levelName){
 
         LeanTween.value(gameObject, (val)=> { cg.alpha = val; }, cg.alpha, 1, 0);
         FadeOut ();
 
     }
 
     public void FadeOut(){
 
         LeanTween.value(gameObject, (val)=> { cg.alpha = val; }, cg.alpha, 0, 1);
 
     }
 }

SceneManager:

 using System.Collections;
 using UnityEngine .SceneManagement ;
 using UnityEngine .UI;
 
 public class ChangeSceneManager : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
 
     }
 
     // Update is called once per frame
     void Update () {
 
     }
 
     public void MainMenu(){
 
         SceneFader1.instance.FadeIn("Title Menu");
         SceneManager.LoadScene ("Title Menu");
         StartCoroutine (Wait ());
         SceneFader1.instance.FadeOut();
 
         //SceneManager.LoadScene ("Title Menu");
         //ScreenFader.instance.LoadLevel("Title Menu");
         //SceneFader.instance.FadeIn("Title Menu");
         //StartCoroutine(ChangeLevel("Title Menu"));
 
     }
 
     public void HowToPlay(){
 
         SceneFader1.instance.FadeIn("How To Play Scene");
         SceneManager.LoadScene ("How To Play Scene");
         StartCoroutine (Wait ());
         SceneFader1.instance.FadeOut();
 
         //SceneFader.instance.FadeIn ("How To Play Scene");
         //SceneManager.LoadScene ("How To Play Scene");
         //ScreenFader.instance.LoadLevel("How To Play Scene");
         //StartCoroutine(ChangeLevel("How To Play Scene"));
     }
 
     public void Play(){
 
         SceneFader1.instance.FadeIn("Gameplay");
         SceneManager.LoadScene ("Gameplay");
         StartCoroutine (Wait ());
         SceneFader1.instance.FadeOut();
         //SceneFader.instance.FadeIn ("Gameplay");
         //ScreenFader.instance.LoadLevel("Gameplay");
         //StartCoroutine(ChangeLevel("Gameplay"));
 
 }
 
     IEnumerator Wait (){
 
         yield return new WaitForSeconds (1f);
 
     }
 
 }


[1]: /storage/temp/73697-screen-shot-2016-07-08-at-82059-pm.png

screen-shot-2016-07-08-at-82122-pm.png (74.2 kB)
screen-shot-2016-07-08-at-82059-pm.png (19.4 kB)
avatar image RakshithAnand El-Deiablo · Jul 08, 2016 at 07:11 PM 0
Share

Hey you are calling fadeOut in fade in method. This will cause both to happen together?

Also last parameter of the "LeanTween.value" is time.. u have made it 0 in fade in.

What exactly is happening? Try calling fade in separately and fade out separately Also you can chain methods to the tweener

Ex: If you want to do something after fade in is complete you can do this: LeanTween.value(gameObject, (val)=> { cg.alpha = val; }, cg.alpha, 1, 1).SetOnComplete(yourfunction/delegate);

Show more comments

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.

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

47 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

Related Questions

Old scene still appears for short time when switching scene 0 Answers

UnloadSceneAsync() does not seem to work with additive scenes. 1 Answer

How can I avoid a framerate drop when asynchronously loading scenes 0 Answers

Canvas gets invisble after changing scene 1 Answer

Multiple scenes loads to multiple clients and server can have a parallel view of each client scene ? 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