Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

play Single Animation Using mecanim? possible?

Discussion in 'Animation' started by Unlimited_Energy, May 2, 2015.

  1. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Threw countless DAYS of trying to figure out how the hell to use Mecanim to play a simple animation file, I still have no idea how to play a simple animation on my character when my character enters a trigger. To my understanding, Mecanim does not Play single animations. It looks like I need at least an Idle animation as the starting state and then the actual animation that Idle will transition to the animation state. I tried to drag my single animation file into the animator window which left a Green bar labeled Entry with a transition to my animation file.

    Supposedly this will not work as the HUNDREDS of threads and countless videos have Idle as a starting state then the animation to transition too. Am I correct in that I need a starting animation and then another to transition too? Why the hell can I not have a single animation play in mecanim? it needs all these complicated transitions from idle to the animation state I actually want to trigger when entering a trigger in game........
     
  2. waythewanderer

    waythewanderer

    Joined:
    Apr 6, 2015
    Posts:
    92
    Is your trigger in a different location, or is it timed? How do you want your character to move to the trigger in the game?
     
  3. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    You can easily create an animation in Unity for your idle, with no movement in it. Then, you just drag that animation in first, and then your other, action, animation into the Animator Controller. You create a parameter to handle the trigger, and then create a transition from the idle to your action. In that transition, you make it triggered by your parameter. Then, you might want to make a transition back to idle, which use can do when the animation ends, or triggered by another parameter. It's actually pretty simple.
     
    Unlimited_Energy likes this.
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Seems like your having a heck of a time seeker. I can relate.

    medhue gives some great advice, but in this instance I don't think that process is needed initially.

    Removing the trigger from the equation - because that's an additional issue which doesn't need to be compounded upon the first problem, did you ever figure out the issue of getting a single animation to play without idle?
    If not check this for reference.
    http://forum.unity3d.com/threads/how-to-change-which-state-entry-transitions-to.321908/#post-2090897
    Setting the animation you have as the default state should play automatically as long as the character controller is set up properly.
    Additionally you mentioned having problems importing animations setup as legacy and generic and the animation not playing. The rig, avatar and animation have to match in order for the animation to play properly.

    If you only want one animation state as soon as the character controller is initialized the animation will play. But you want to pause this animation state until the trigger is activated. I believe setting the animator speed to 0 will pause, and setting it back to 1 will play normal playback.
    http://docs.unity3d.com/ScriptReference/Animator-speed.html
    The trigger can be the pause / unpause, though I'm no coder so I don't know how efficient this is .

    Additionally you could use the technique medhue suggested and set the transition to happen on trigger enter.

    If you've already solved the single animation issue - here are a couple recent trigger related posts which may be helpful.
    I'm not a coder so I can't accurately decipher the code you posted in the other thread, but these may help.
    http://forum.unity3d.com/threads/un...-backwards-has-no-effect.321579/#post-2090908
    http://forum.unity3d.com/threads/triggers-getting-stuck.314760/#post-2072879
    http://forum.unity3d.com/threads/do...n-not-playing-animations.321610/#post-2090556

    If you continue to struggle with code you may want to consider Playmaker from the asset store.
    It's been a godsend for me personally. :)
     
    Unlimited_Energy likes this.
  5. anIndividual7

    anIndividual7

    Joined:
    Apr 26, 2015
    Posts:
    12
    Sounds like your having similar issues with simple setups as I was over here http://forum.unity3d.com/threads/dont-move-with-my-stuff-when-not-playing-animations.321610/

    I would draw your attention to what a dev said:
    In my case (i was wanting to only play ONE animation at the right time) I have ended up just disabling the mecanim component completely to stop it screwing with my stuff when its animation is not required

    Mecanim describes non character animation as 'generic', well you're generic mecanim, you're genericly bad at the basics that the legacy system got right.
     
    Last edited: May 6, 2015
    Unlimited_Energy likes this.
  6. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    I think it really depends on how you like coding these things, or if you are a coder vs an animator. Me, I love mecanim, whether for characters or not. I'm not saying it could not be improved, but it does make things easy. I've actually had to force coders to use it too, on a number of jobs. Once they dig deeper into mecanim they understand why it is good to use. Now, when I do make animated non character items for games, I include the animator controller, just so the coder can see how I'm using it.
     
  7. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    concur medhue. Personally I hate even having to attach a copy/paste script to things because I feel like I'm loosing control of whatever it is. I bet a lot of coders feel the same way when they have to use something visual like mecanim instead of keeping total control of everything via code.

    I haven't used mecanim beyond character setup yet, but I will be soon. Sorry for changing subjects.
    Wonder which workable solution OP @sunseeker1988 used.
     
    Unlimited_Energy likes this.
  8. anIndividual7

    anIndividual7

    Joined:
    Apr 26, 2015
    Posts:
    12
    @medhue: I think I came off a bit too snarky, but i'm not coming from a coding angle here, i'm absolutely on the art side of things :)

    I would point out that from an animation point of view the workflow of animating positions, rotations, colors & properties etc is identical to the legacy system - & i do like it - unity is excellent on the editor preview performance side of things.

    Its just the behaviour of the animator when you set a keyframe that seems confused to me. It should only "take control of this property and start to write value" when its on a state with that animation.

    Its behaving a more like a fixed global timeline that a state machine & should treat states with animations attached as individual timelines - thats what they are after all.
     
  9. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469



    I think its not doing what I want because I have the parameters, conditions and my code not working together as it should. I want my main character "tron" the paddle to animate once when it comes into contact with the white box. Im not sure I have my scripting, parameters and conditions set up correctly to achieve this. I made a video to show you guys what I'm working with. I'm very new to all of this so from the bits and pieces ive tried to gather from various videos and websites I think I still do not have it set up properly.


    I do want to let you all know the animation "Idle" dose not animate. I only created an idle animation because all of the videos I watched had Idle as the starting animation and THEN transitioned to the animation they wanted animated. I do not have to use Idle animation if thats an option for animating from entry to Bump.....I'm just lost here
     
    Last edited: May 13, 2015
  10. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    After watching the video, you do have a problem with your parameters, and this could be causing all your issues. So, you have the default idle, and that transitions into the bump animation and then back to idle. The transition in, should probably be a boolean, set to true. The transition out of the bump animation should not use the bump parameter to go back to idle. What it should use is time. If you set no parameter, then the transition will use time as it's default.

    What you have in the video, is the transition in, and transition out, using the exact same trigger, so the bump animation never actually plays. So, the system is being told by you to goto this bump animation, but then immediately back to idle. I hope everything I'm saying makes sense.
     
    Unlimited_Energy likes this.
  11. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    It does make sense thanks a ton. I had a trigger on my main character. I took the trigger off and left the trigger on the cube and it works. It plays the animation when my character comes into contact with the trigger on the cube, but my animation plays over and over in a loop. i just want the animation to play once.
     
    Last edited: May 14, 2015
  12. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    Make sure in the transition out of the bump animation, you have Has Exit Time checked.
     
    Unlimited_Energy likes this.
  13. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    awsome it works but when my character enters the trigger for a second time it will not play any animation again no matter how many times it moves into the trigger.
     
  14. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Guess - The trigger needs to be reset when character exits so it can be active again.
     
    Unlimited_Energy likes this.
  15. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    thats what I figured but any idea how to do that?
     
  16. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I don't know if that has to be done in code or not. Can the animation event, when the animation completes reset the trigger?
    I use PlayMaker :)
     
    Unlimited_Energy likes this.
  17. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    everything working now thanks guys
     
    theANMATOR2b likes this.