Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Variables changed in animation reset after animation is over

Discussion in 'Animation' started by lightspeedlazer, Jun 22, 2020.

  1. lightspeedlazer

    lightspeedlazer

    Joined:
    May 16, 2020
    Posts:
    3
    First of all, I have very little experience with Unity, so expect some simple solutions. I am trying to make a "realistic" pump action shotgun. The shotgun is reliant on the variable BarrelState, which basically tells you what is in the chamber. The three values of BarrelState are 0 == No shell in chamber, 1 == Unfired shell in chamber, 2 == Fired shell in chamber. In order to fire, BarrelState has to be 1. In the Fire animation, it will set BarrelState to 2 immediately. In the "Pump with Reload with Ammo" (PRA for short), BarrelState goes from 2(Begining)->0(Ejection)->1(Loading new shot in chamber), like a real pump action shotgun. The problem is with the Animation. It resets PRA about 2-8 times each fire when it should only do 1. Here is a screenshot of the Animator, PRA entry conditions, and the PRA animation itself.
     

    Attached Files:

    Last edited: Aug 1, 2020
  2. gabrimo

    gabrimo

    Joined:
    May 2, 2015
    Posts:
    92
    Well, if you're positive that things are happening twice or several times. I would ensure that the execution happens only one time at the certain condition with a bool or something.
     
  3. lightspeedlazer

    lightspeedlazer

    Joined:
    May 16, 2020
    Posts:
    3
    Update:

    I have figured out that the variables reset after the animation is over, so I made a function to set the Barrel State and it works fine.
     
    Last edited: Aug 6, 2020