Search Unity

Animator float parameter access error (solved)

Discussion in 'Animation' started by Anjoom, Sep 4, 2017.

Thread Status:
Not open for further replies.
  1. Anjoom

    Anjoom

    Joined:
    May 15, 2017
    Posts:
    3
    tl:dr
    Code (CSharp):
    1. public void ActivateFadeFromWhite ()
    2. {
    3. transitionPanelAnimator. SetFloat ("FadeValue", 1f);
    4. }
    Isn't working. Any suggestions?

    I'm following the Brackeys tutorial 'How to make a game'. It's a tutorial on creating a simple casual game. I went through the whole thing and got a working game, but it lacked polish. So I decided to create some fade animations between levels and such. Then, I thought that my code was too complicated, and went on to optimize it. Now, all this is just extremely oversimplyfied. The horrors I went through, only me and god himself can understand. I'm stuck at a certain function failing to run properly.

    Now, some backstory-
    I have a GameManager empty gameobject in every scene with a GameManager script attached. In the Start() function of this GameManager script, is a call to the ActivateFadeFromWhite() function in another script called TransitionManager, so that any time the GameManager is activated in a scene (which, as it is present and active in every scene from the beginning, is always), a completely white panel fades from white to transparent, thus giving a fade impression. TransitionPanel is a completely white UI Panel.Whenever I want to do a fade in or fade out, I activate animations which changes the alpha values of the TransitionPanel. These two animations are activated through a float parameter in the animator of the TransitionPanel gameobject. In the above-mentioned ActivateFadeFromWhite() function, the TransitionManager script changes the FadeValue float parameter in the TransitionPanel's Animator component. This, in turn, causes the Animator to trigger the FadeFromWhite animation. After the animation is over, an AnimationEvent in the animation itself triggers a function in TransitionManager called FadeFromWhiteEvent(). This function calls on the GameManager script to do a StartGameplay() function.

    This is as much as you possibly need to know. Now, let's get to the exact trouble.
    The ActivateFadeFromWhite() function in TransitionManager is somehow not working. There is an error stating 'NullReferenceException' and pointind to the ActivateFadeFromWhite() function in TransitionManager. I did Debug.Log wherever I could, to trace the problem to it's roots. The best piece of info that I could gather was that the below function had something wrong. Specifically, the SetFloat part.

    Code (CSharp):
    1. public void ActivateFadeFromWhite ()
    2. {
    3. transitionPanelAnimator. SetFloat ("FadeValue", 1f);
    4. }
    What surprises me is that this problem only happens with the StartMenu and EndMenu scenes. All the other 10 game levels that actually are playable levels aren't affected by this. So, it must certainly be something wrong with the way the Menu scenes work. By this, it can be confirmed that ythescripts are working perfectly, and that there is something wrong with the way the 2 menu scenes are set up.

    I was hoping some of you could help me with finding out what's wrong. Sorry for the long post. I'm new to the Unity forums. It's my first post. Thanks in advance. Please ask me if any more details are needed.
     
    Last edited: Sep 4, 2017
  2. Anjoom

    Anjoom

    Joined:
    May 15, 2017
    Posts:
    3
    tl:dr
    Um... I fixed it

    The Transition Panels of the game levels were part of a prefab, but the Transition Panels of the Menus weren't. Thus, the outdated Transition Panels of the Menu Screens must have caused the problem. I just prefabed (Is that a word?) the Transition Pnale from a game level and
     
Thread Status:
Not open for further replies.