Hi all,
I add a PNG sequence to the animation timeline and I added an Event : “Fire” .
I also connected the animation to “Any State” in the animation window.
Why it doesn’t work?

Thanks Dror
Hi all,
I add a PNG sequence to the animation timeline and I added an Event : “Fire” .
I also connected the animation to “Any State” in the animation window.
Why it doesn’t work?

Thanks Dror
Have you added an Animator to you GameObject and assigned the motion clip?
Hi Rob, thanks for your response.
I added an Animator to the GameObject , now it works… sort of…
Instead of starting the animation when I shoot , its shoots etch frame (with the animation).
There’s no “Fire” action in the update , only by the Space key input (without the animation the shooting work fine)
The event don’t work… any idea why?

Can you take some screenshots;
I’m not shore i understood all what you’re asking for… (I’m starting to think that I’m missing a big part here )
you can see the Animator view above.
and that the inspector of the GameObject:
Hi,
Sorry, I should have explained in more detail.
So, in the animator screenshot you included about you have two states that you have created, PlayerGameObjectIdile and playerFire. Can you select those, one at a time, and then take a screenshot so that I can see the Inspector view (for each).
Additionally, if you click on each of the transitions (the arrows between those two states) and do the same, so we should end with four more screenshots;
Hope this makes a bit more sense 
I didn’t even know that the transitions have properties in the Inspector.




Don’t worry, you come onto this a bit more in Glitch Garden 
Ok, so looking at the screenshots…
Both states have the Has Exit Time checked on the transitions, if you expand Settings you will see there is a duration, and then just under that there is the transition percentage with a fraction of the above duration applied to the transitioning into the next state (as displayed by the diagonal blue bar on the time line in your screenshots).
What is happening with the animation is that it starts off in the idle state, does a cycle of it’s animation, then moves to the firing state, does its cycle and then goes back to idle… repeat…
What you could do;
add a parameter within the Animator, perhaps calling it isFiring, and setting it as a trigger.


remove the Has Exit Time option from the Idle state
remove the Fixed Duration option from the Idle state

(note, in this screenshot the second state is called Attack)
check that the Condition is set to isFiring

With this in place, the only way the idle animation can move on to the firing animation is with this trigger being set.
On the transition returning from firing to idle;
select the Condition and click on the minus sign to remove it

make sure that Has Exit Time and Fixed Duration are checked and have their default values
What you have now is an animation that will only move to firing from idle if the trigger is set, and, will perform its firing animation for a specific duration before returning to the idle state. You may need to adjust this depending on what you are trying to do, for example if this is for a laser shot that wiggles up the screen you may want it to just keep wiggling until you destroy the game object.
So the last part is to set the actual trigger. You can do this in code. Without knowing exactly which objects you have and what is attached to what this is a little trickier to advise on but I will have a go…
When you detect your player pressing the key to shoot you will need to use something along the lines of;
animator.SetTrigger("isFiring");
In the above, animator is a private variable I have set to type Animator.
In a Start() method I then use animator = gameObject.GetComponent<Animator>(); to get the Animator component attached to this game object.
This may vary on your project as to how to find the animator, so change the code accordingly, the main thing is that you get a reference to the animator and then set the trigger.
Give the above a go, if you get stuck give me a shout. 
Aaaaa!! It’s working! Thanks!
When I thought about adding animation to all actions, I thought that I will add an event to the timeline , select the function and that all. It’s work great with the trigger, so… what are the events are for?
I still have some issues … if I can bother you one last time.
The first issue is that Unity is waiting for the idol animation to be over and only then starts the fire animation.
The second one is that it fires twice etch key down (when I remove the animation it shots once etch key down)
I tried playing with the durations in the inspector but no luck.
Thanks again.
Dror
Aaaaa!! It’s working! Thanks!
Great news! ![]()
When I thought about adding animation to all actions, I thought that I will add an event to the timeline , select the function and that all. It’s work great with the trigger, so… what are the events are for?
It’s covered pretty well in the Glitch Garden section, so you have that to look forward to
You can influence the animation states with the events from the animation timeline, you simply wire them up to methods, in fact, you could set your trigger this way, e.g. from the event in the animation timeline, calling a method, running the code to set the trigger. One of the disadvantages, would be that it would be called at that same place in the animation every time. Now, I say disadvantages, obviously it depends what you are trying to achieve. If you want something to happen based on another action then the triggers may be more use.
You might have an animation for the engines firing on a space ship lets say, and when they get to a specific part of that animation you want to run another piece of code, perhaps flash the word “Engines Primed” on the screen or something (I am making this up as I go but hopefully you get the idea). That would be something that you could do from code and wouldn’t rely on the animation states for.
I still have some issues … if I can bother you one last time.
It’s no bother, I’m happy to help ![]()
The first issue is that Unity is waiting for the idol animation to be over and only then starts the fire animation.
That would be indicative of having the Has Exit Time and/or Fixed Duration being set on the transitions. It basically controls how long the previous state will run for before the next is run. So, if you are having to get through ALL of the idle state before you can fire, remove those options (see screen shot above)
The second one is that it fires twice etch key down (when I remove the animation it shots once etch key down)
That one might be a bit trickier to solve without seeing the code. What I would suggest though, initially, is starting from a more simple place. So, in the code that handles the fire button/key being pressed, pop a Debug.Log() statement in there and see how many times that is called when you fire. If that appears more than once (like the animation) then we have discovered why, e.g. several detections within the same frame. Try that to start with and see what you get.
Let me know ![]()
Updated Tue Feb 21 2017 17:43
Just as a secondary thought - do you still have the events on the animation timeline setup to call the fire method / animation? That could also potentially explain the duplicate animation.
That is all quite interesting! I am going to have to go over animation again in Glitch Garden 'cause it didn’t really sink in.
… was one thing that I was wondering about so that is plain enough thanks @Rob.
Time to fire up Glitch Garden …
Glad you found this of use Paul 
Now it’s working!
@Rob thanks a lot for your help! There’s so match more I want to do with Lesser Defender but I think I will continue to
Glitch Garden to learn, and then I will return to finish that game as I wanted and more.
Again Thanks! Your Great!
Hi,
That’s great to hear and you are more than welcome. What was it in the end causing the double firing?
You will find in Glitch Garden it covers the dope sheet / animation time line using the events as you had started doing, then later it swaps out some of that functionality for the parameters on the animator. So you’ll get to see both in action.
Glad you got your laser defender working how you had wanted. 
It was the Event on the time line (I forgot to remove it).
I saw the introduction to Glitch garden and understood that they will cover all I wanted for Laser Defender.
I’m an animator and the moment I finished laser defender I wanted to add animation to everything, i guess i have to be patient ![]()
It was the Event on the time line (I forgot to remove it).
Aha! Cool, so you have seen now that you can do it either way, but the choice may come down to how you want to control it.
I saw the introduction to Glitch garden and understood that they will cover all I wanted for Laser Defender.
Fantastic! If/when you post a link up to your game when it’s done, if you remember can you tag me using @Rob, I’d love to see it with all the animations and so on ![]()
I’m an animator
lol - now I feel a bit daft mentioning things like the dope sheet and so on… you’d have known all of this I guess from other products… sorry, wasn’t trying to teach you to suck eggs as the phrase goes, very difficult to tell what experience people have when you reply on here, at least until you see them post really frequently etc ![]()
and the moment I finished laser defender I wanted to add animation to everything, i guess i have to be patient
hehe, makes perfect sense, and that’s great, as it’s that level of enthusiasm that will keep you moving forward with the whole course and the projects you work on ![]()
Looking forward to seeing your projects as and when you are ready.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.