Issue with animator refreshing states.
Ehi there! There is an issue i'm struggling to resolve concerning the animator mechanics, i'm not sure if it's a bug or i really did a huge mistake in programming, even though the script i'm having problems with is extremely simple. First of all i have got a prefab with a 4 states animation layer. They work like this:
As you can see there's 4 states 2 for when the door is in motion and 2 for the idling animation(open/close idle).
The script managing the transitions is this one:
if (animate) {
if (!on) {
interactable.transform.GetComponent<Animator> ().SetBool ("up", true);
interactable.transform.GetComponent<Animator> ().SetBool ("idle", false);
StartCoroutine (AnimTime ());
on = true;
} else {
interactable.transform.GetComponent<Animator> ().SetBool ("idle", false);
interactable.transform.GetComponent<Animator> ().SetBool ("up", false);
StartCoroutine (AnimTime ());
on = false;
}
}
IEnumerator AnimTime(){
yield return new WaitForSeconds (animtime);
interactable.transform.GetComponent<Animator> ().SetBool ("idle", true);
StopCoroutine (Tempo ());
}
Once again it's notable that the script is extremely simple and should work (but then again it's not so i'm just assuming)
Given all of this.
When running, the variables in the script are changing and i can keep track of the script visually, confirming that it's working.
On the animator side the thing is not working. Once the first animation as been performed and is idling (the door has been opened and has stopped moving the animations die). The script is still performing actions but when i click to close the door the variables in the animator start to flicker, show incorrect values (even though the script is sending the right ones) and the whole thing become a mess.
Before the latest update the script was working oddly anyway (meaning some doors were perfectly working while others didn't work at all or work when they felt to) but i wonder if the update could have f****d it up even more.
Any suggestion is welcome and needed.
Answer by AeROLP · Aug 26, 2017 at 05:36 PM
I think i might have figured it out.
The problem is probably in the animTime.
It has to be spot on as the length of the transition to avoid overlapping of information and sending the entire "two-way switch" apparatus down the sink.
And since some doors had different timed animations their transitions of state were also different.
It's working now, but i need more confirmation, if anyone ever used this method and had my same problem could kindly confirm so i can be sure?
Thanks a lot.
Your answer
Follow this Question
Related Questions
[C#]How to save a list of items to use in another script and it's not a player prefs type of list? 0 Answers
Trying to animate using Breadcrumb(Asset) 0 Answers
Animations get screwed up when I add OnAnimatorMove function 0 Answers
Falling blocks skip animation while upside down 1 Answer
How too climb a ladder with the FPS Controller correctly 0 Answers