Animation playing backwards never stops.

Newbie here, please bare with me. Basic question: Don't animations playing backwards stop when they reach the beginning (i.e. frame 1)?

I have an extremely simple animation of a door like element that is opened and closed through scripting. The direction (open/close) can be reversed a random number of times while the door is moving. I am using the animation itself to set a gamestate when the door is fully open or closed, by checking animation.isPlaying in Update(). Very simple stuff :-)

This works fine when the animation is playing forward (positive speed) - animation.isPlaying evaluates to false when the last frame is reached. However, playing backwards, isPlaying stays true and animation.time keeps decrementing towards negative infinity (I presume), but without any animation playing (since there is nothing before frame 1).

Is this a bug/feature or am I missing something?

The animation is exported from 3ds Max in FBX 2010 format and consists of only two elements, with one element rotating relative to the other (it's a swing door). Animation contains only two frame, with frame 1 being the open state and frame 50-something being the closed state (door fully rotated). Wrapmode is set to Once in Unity.

I am currently checking animation.time instead to find out when the door is back at the fully open position, but using isPlaying seems like a more elegant solution if it worked.

Anyone?

Here is a code example: I edited out only the minimum necesarry for understanding the problem and added a few comments. The problem occurs if AbortClosure is called after Close is called and animation is still playing: Animation plays backwards at the correct speed, but AnimationState.isPlaying remains true and so the block at line 75 is never reached. Instead AnimationState.time is used to check when the animation is back at the beginning.

Please ignore the inconsistent use of the 'this' keyword :-)

1   using UnityEngine;
2   using System.Collections;
3
4   internal enum TubeState
5   {
6       Idle, 
7       Closing,
8       Opening
9   }
10
11  public class TubeController : MonoBehaviour {
12
13      private bool isOpen;
14      private GameObject tubeAssembly;
15      private AnimationState animCtrl;
16      private bool openCloseInProgress;
17      private TubeState state;
18
19      
20      public void Start()
21      {
22          state = TubeState.Idle;
23          tubeAssembly.animation.Stop();
24          openCloseInProgress = false;
25      }
26
27
28      public void Close()
29      {
30          if (state == TubeState.Idle || state == TubeState.Opening)
31          {
32              animCtrl.speed = animCtrl.length / this.transform.parent.GetComponent<TubeSystem>().TimeToClose;
33              if(state == TubeState.Idle)
34              {
35                  this.tubeAssembly.animation.Play("close lid");
36                  this.openCloseInProgress = true;
37              }
38              this.state = TubeState.Closing;
39          }
40      }
41
42
43      public void AbortClosure()
44      {
45          if (state == TubeState.Closing)
46          {
47              animCtrl.speed = -animCtrl.length / this.transform.parent.GetComponent<TubeSystem>().TimeToOpen;
48              this.state = TubeState.Opening;
49          }
50      }
51
52
53      public void Update()
54      {
55          if (this.openCloseInProgress)
56          {
57              switch (state)
58              {
59                  case TubeState.Closing:
60                      {
61                          if (!tubeAssembly.animation.isPlaying)
62                          {
63                              this.isOpen = false;
64                              this.state = TubeState.Idle;
65                              openCloseInProgress = false;
66                              //DO SOME STUFF HERE NOW THAT LID IS CLOSED
67
68                          }
69                          break;
70                      }
71
72                  case TubeState.Opening:
73                      {
74                          if(!tubeAssembly.animation.isPlaying){
75                          // THIS BLOCK IS NEVER REACHED!
76                          }
77                          else if (animCtrl.time <= 0)
78                          {
79                              ///THIS BLOCK IS
80                              this.state = TubeState.Idle;
81                              tubeAssembly.animation.Stop();
82                              openCloseInProgress = false;
83                              //DO SOME STUFF HERE NOW THAT LID IS FULLY OPEN AGAIN
84                          }
85                          break;
86                      }
87              }
88          }
89      }
90  }

I've never really done anything with animation, but maybe in the import settings there is a loop option (there is one for audio...)

I am pretty tired today, so forgive me if I have overlooked something. I have taken a quick look over your code, and it appears that the if in the switch (!tubeAssembly.animation.isPlaying) would not be met because you have stopped any of the switch being reached by the update due to openCloseInProgress being set to false. At the start of the update we have:-

if (this.openCloseInProgress)

And then you terminate openingCloseProgress in the else if:-

                case TubeState.Opening:
                  {
                      if(!tubeAssembly.animation.isPlaying){
                      // THIS BLOCK IS NEVER REACHED!
                      }
                      else if (animCtrl.time <= 0)
                      {
                          ///THIS BLOCK IS
                          this.state = TubeState.Idle;
                          tubeAssembly.animation.Stop();
                          openCloseInProgress = false; // Does this not cancel out any conditions being met in the update function?

                      }
                      break;
                  }

[edit]

Or could it be that here you should be checking its true instead of false?

             case TubeState.Opening:
                  {
                      if(tubeAssembly.animation.isPlaying){ // Should this be true?

                      }