Search Unity

Tweaking screen transitions controller not to fire every time

Discussion in '2D' started by Tigro, Mar 2, 2021.

  1. Tigro

    Tigro

    Joined:
    Apr 25, 2014
    Posts:
    58
    I'm making a simple screen transition system for my game which consists of two states firing the right clips (one for the starting half od the transition animation, one for the ending one) and a condition between the end and start one which is set to true when user wants to change the level (so that the Start animation would fire in the previous animation and the End in the new one).



    This is cool and all but poses two problems - firstly, the game starts with the End phase animation which looks a bit weird. Secondly, since the Restart button in the main game just reloads the level, it causes the End transition to fire every time too which looks weird and out of place.

    How would I go about tweaking the Animator so that the End phase only runs when I actually change the level as opposed to when starting the game or reloading the current scene?
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    You can make the Start animation/state the default state. Just right click it and make it default and it will become the orange state.
     
    Tigro likes this.
  3. Tigro

    Tigro

    Joined:
    Apr 25, 2014
    Posts:
    58
    Yeah but regretfully this does not really solve the problem :( I'd still need to somehow communicate to Unity that on some LoadLevel() calls it should fire the animations while on others it should not - and therein lies the problem. To better show what I'm having problem with, here's the video of how it plays out right now:


    As you can see, the way it is wired up now makes sense - we fire the ending animation every time and fire the Start animation with the trigger whenever we load a new level (so that a coroutine plays it in the previous level, loads the new level, and then it - again - automatically plays out the End). Thing is, this does not make sense in all situations, which can be seen in the video - ie. on every restart of the game, the End animation flashes which does not make sense cause we did not move from menu to the game level, just restarted (ie. loaded again) the main game scene. Similarly, the End animation flashes when starting the game (not visible in this clip but you get the drift) cause it fires automatically when the menu is loaded, even though in this context it's not what we want (contrary to moving from tutorial or main game, both of which can be seen in the video, when it does make sense for the End anim to play automatically having loaded the level).
     
  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    Its a bit hard for me to understand which animation is the start and which is the end, but i get your issue. You are able to create animation parameters that can tell the game when to fire which animation. This i assume you know. How you are calling those in your code is another story. Can you post your code where you are calling your animation transitions?
     
    Tigro likes this.
  5. Tigro

    Tigro

    Joined:
    Apr 25, 2014
    Posts:
    58
    Ah, I managed to solve this :) I just changed my methodology of handling the transitions from having a separate level loader of sorts in each scene to just having one with DontDestroyOnLoad() and then defaulting my animation controller to an empty state with triggers for both Start and End. Then, I just use the persistent game object to handle setting and resetting those as I see fit (ie. not playing the Start/End cycle when restarting a level but doing so when actually going from the menu to the game or to the tutorial). Thanks for the help! ;)
     
  6. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    Ahh the singleton method. Looks like a good use of it. Nice work, glad you got it working properly.
     
    Tigro likes this.