Search Unity

2017.4 load scene kills animation fade

Discussion in 'Animation' started by pRoFlT, Mar 22, 2018.

  1. pRoFlT

    pRoFlT

    Joined:
    Dec 20, 2014
    Posts:
    27
    okay i just killed an hour trying to fix a stupid fade mechanic between scenes when i really wanted to work on my game. which i havn't had time in months. So i will post and give up for now. Maybe someone can point out my mistake.

    Running Unity 2017.4, Was working in 4.6 though 5.X now broke. also scenloaded trigger has changed so i had to make a change to that code. so maybe that broke it?

    Anyways on scene change i do this


    //Use invoke to delay calling of LoadDelayed by half the length of fadeColorAnimationClip
    Invoke("LoadDelayed", fadeColorAnimationClip.length * 0.5f);

    //Set the trigger of Animator animColorFade to start transition to the FadeToOpaque state.
    animColorFade.ResetTrigger("fade"); // i did this because of something? bug maybe? doesn't matter either way if i dont do this.
    animColorFade.SetTrigger("fade");

    and then in LoadDelayed i have

    public void LoadDelayed()
    {
    //Pause button now works if escape is pressed since we are no longer in Main menu.
    inMainMenu = false;

    //Hide the main menu UI element
    showPanels.HideMenu ();

    //Load the selected scene, by scene index number in build settings
    //Application.LoadLevel (gameManager.Level); // old way

    SceneManager.LoadScene(GameManager.instance.Level);
    }


    fade trigger inside the animation just changes alpha on a black image from 0 to 1 and back to 0.

    when scene loads the animation stops. and i get about 0.4 -0.5 alpha. like as soon as the scene loads the animation stops and i see animation cycle go back to idlestate.

    and if i try to change alpha by hand at this point it is locked!!!!! i dont touch this anywhere else in code. why is it locked!!! ahhhhhh

    I even tried to change the animation. fadeout fadein and trigger fadein animation using the scene load delagate from the scenemanager. but that also does not work and jumps out of the fadein right away. this is frustrating. i just want to work on my menu look :(

    any help would be nice. please. thanks.

    p.s. this code resides in my ui script controller that has dont destroyonload. so it is persistant through the scene changes. it has fade image on it.

    p.p.s. sorry if this has already been answer somewhere in the universe. i did not find the answer. the universe is big.
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    It would probably be much easier to use Animation Events for this. At the end of your Fade animation, add an animation event that invokes your load function. Animation Events can be found in the Animation editor and look like "wedges", put one of these at the end of the animation. Click on it and it will allow you to select a function on your GameObject (it needs to be public).

    And to remember to remove the Invoke() from your code.
     
  3. pRoFlT

    pRoFlT

    Joined:
    Dec 20, 2014
    Posts:
    27
    So im not sure i can get the effect i want that way?

    End scene/level Fade out. load new scene/level. fade back in.

    To be clear it was working. I did nothing to break it. New Unity 2017.4 did this. maybe even all 2017.X. I've not worked on this for awhile.

    My script would, half way through the animation, load a new scene. while continuing the animation. This does not seem to work anymore. once the new scene is loaded the animation ends and goes back to idle state. The end of my animation never finishes.

    I used the code from this asset store https://www.assetstore.unity3d.com/...21691270-103640392.1493700650#!/content/40465 it's a year or two back. I've been working on this game, off and on, for awhile now.

    Which now that i look at the "Game Jam Menu Template" i used. it has changed to work with the newer scenemanager and some other changes. i will look through that and see if maybe they did something to fix this issue already.

    I will pull out some of my scripts into a template game project and see if i can get this animation event to work instead. I just need the fade back in to work once the level is loaded....ill need to think about this a little and play with it some.
     
  4. pRoFlT

    pRoFlT

    Joined:
    Dec 20, 2014
    Posts:
    27
    Okay digging through code. and im not sure why this is causing this.

    i found a work around i put in place for 2017.3 bug on canvasas. i thought it's 2017.4 maybe they fixed this. so i removed it and bam, fading is kind of working again? wth?



    private void RefreshCanvas() // stupid 2017.3.f1 bug have to refresh canvas to clear out things. temp hacky fix. should get fixed in next unity release
    {
    // mainCanvas.SetActive(false);
    // mainCanvas.SetActive(true);

    // and now in 2017.4 this is causing issues i think! strange. removing and testing now :)

    }


    I forget the problem. but i had to disable enable the canvas in order for my ui to work properly. may have only been on android. but i think it was happening in windows too.

    so removing this hack in the code made things work again. not sure how these are related.
     
  5. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    At the end of your fade out, your Animation Event would trigger the load method and load the next scene. Then, you don't have to calculate the length of the animation and you can be sure that the entire fade has completed before the load occurs. A much easier and less error prone way of doing it. Lets say that you change the animation in some way, then you won't have to redo anything in your code, since the Animation Event is what triggers the actual load.
     
  6. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Might consider rolling back to latest 2017.3.x version. It seems from others 2017.4 is not a stable build.