• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by You! · Jun 18, 2012 at 08:38 PM · animationparentblendthrow

animation.Blend() not playing

I have to have an animation in a parent object play in order for some events to work (because it has an animation event). The rest of the script which would activate the animation works (I checked using debug logs), but the animation itself won't play. I need the animation to be able to be played while the character is moving (this is why I thought I'd use animation.Blend()) Here's the code for the animation so far:

 var MainM : GameObject;
 var caseSwitch : boolean = true;
 
 function Start(){
 MainM = transform.parent.transform.parent.transform.parent.transform.parent.transform.parent.transform.parent.transform.parent.transform.parent.transform.parent.transform.parent.gameObject;
 
 //MainM is a very distant ancestor!
 MainM.animation["Throw"].wrapMode = WrapMode.Once;
 }
 
 function Update(){
 //[...]
 if(Input.OnMouseButtonDown(0) && caseSwitch){
 MainM.animation.Blend("Throw");
 caseSwitch = false;
 }
 }

I've also tried to use animation.Play() and animation.CrossFade() instead of animation.Blend(), which yielded the same, nonexistent results. Also, I've tried to, instead of using transform.parent, assign the game object in the inspector. No change in results.

==========================================================================================

Edit: animation.Blend(), animation.CrossFade(), and animation.Play() have all failed. The source of the problem is most likely something with the animation itself. I have tried re-making the animation with no success. Any suggestions to help with re-animation and fixing the problem this way is appreciated. Thank you.

==========================================================================================

Comment
Add comment · Show 41
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Jun 18, 2012 at 08:45 PM 0
Share

You aren't actually doing it every frame?

avatar image You! · Jun 18, 2012 at 08:50 PM 0
Share

Nope... There's some if statements which control whether or not the animation plays. These if statements also affect other variables (like the number of objects that the player has available to throw). The rest of the stuff is activating (once, not continually), but the animation isn't playing at all. I'll add a bit to the shown code to symbolize this.

avatar image whydoidoit · Jun 18, 2012 at 08:51 PM 0
Share

Yeah what I mean is that Blend may restart the animation every time you call it so it should be triggered and not called continually when in that state.

avatar image You! · Jun 18, 2012 at 08:54 PM 0
Share

I'm not calling it every frame... The throwing system is set up to where when the projectile reaches it's target, it re-activates a boolean (in this case caseSwitch) to be true, so that it is called when the mouse button has been pressed and the projectile has finished it's own stuff.

avatar image whydoidoit · Jun 18, 2012 at 08:57 PM 0
Share

Are your animations on layers?

avatar image You! · Jun 18, 2012 at 08:59 PM 0
Share

EDIT: No, I am not using layers. (Thanks, Sir Google!)

avatar image whydoidoit · Jun 18, 2012 at 09:07 PM 0
Share

Well there are animation layers too - higher values get to do something, but then you are really just looking for the event which isn't happening - that would still happen, just the animation wouldn't do anything if it was on a lower level. Hmmm.

avatar image whydoidoit · Jun 18, 2012 at 09:09 PM 0
Share

It anything else doing a Play() - which would stop your Throw?

avatar image You! · Jun 18, 2012 at 09:11 PM 0
Share

Yeah, the animation event changes a variable which detaches the projectile and moves it toward the target, which isn't happening at all. The animation does exist, has the events, and plays in the animation window (just double checked).

Edit: There's a running animation (animation.Play()) and a sword swinging animation (the sword is in the opposite hand of the throwing hand, using animation.CrossFade()). Both of them work, and they work together well.

avatar image whydoidoit · Jun 18, 2012 at 09:34 PM 0
Share

So how about Debug.Log on the animation["Throw"].enabled and animation["Throw"].speed in update do see if it ever changes?

avatar image You! · Jun 18, 2012 at 10:05 PM 0
Share

The speed is always 1 and enabled is always false, even when I attempt to activate the animation.

avatar image whydoidoit · Jun 18, 2012 at 10:06 PM 0
Share

Ok set enabled = true, rather than doing the Blend - set weight to 1.

avatar image whydoidoit · Jun 18, 2012 at 10:07 PM 0
Share

It feels like something else is doing a Play and stopping it.

avatar image whydoidoit · Jun 18, 2012 at 10:08 PM 0
Share

Perhaps if this went first, your sword did play and your animation did the fade then the latter two would work and this wouldn't.

avatar image You! · Jun 18, 2012 at 10:19 PM 0
Share

Ok, so I need to...

 $$anonymous$$ain$$anonymous$$.animation["Throw"].enabled = true;

...before the animation...right? Then...

 $$anonymous$$ain$$anonymous$$.animation["Throw"].weight = 1;

...right? The three comments in a row kinda confused me...especially the last of the three (I don't know why...).

avatar image whydoidoit · Jun 18, 2012 at 10:24 PM 0
Share

Sorry, thinking on two tracks at once. Yes do that rather than Blend and see if it works (really not confident as we are effectively just turning it on fully blended), but step by step is good.

avatar image You! · Jun 18, 2012 at 11:06 PM 0
Share

I tried that code (no success), and then tried that code with animation.CrossFade() (seems like overdoing it, but was still not successful).

Just to check, I put on a Debug.Log() to see if it will return the correct game object for $$anonymous$$ain$$anonymous$$. It was successful...

avatar image whydoidoit · Jun 18, 2012 at 11:10 PM 0
Share

Right - so we've removed the possibility that something is happening with Blend. So how about this: stick a Debug.Log infront of the animation Play's you have and here and make sure that this is being called after any play. Because any Play will stop all other animations on the same layer (at least).

avatar image whydoidoit · Jun 18, 2012 at 11:10 PM 0
Share

Crossfade will fade out other animations on the same layer. So maybe you should put Throw on a different layer?

avatar image You! · Jun 18, 2012 at 11:28 PM 0
Share

I put throw on layer 3. I put the Debug.Log after the animation calls (for some strange reason) and found that, even though the throw animation didn't play, the debug log worked. The inverse was true with the attack animation.

avatar image whydoidoit · Jun 18, 2012 at 11:34 PM 1
Share

Oh really ugh. Really sorry, I'm going to have to leave you too it for a bit. I'll think on...

avatar image You! · Jun 18, 2012 at 11:37 PM 0
Share

Thanks, @whydoidoit.

avatar image whydoidoit · Jun 19, 2012 at 11:02 AM 0
Share

Ok so just to check that there isn't something really weird going on. If you Debug.Log animation["Thow"].enabled just after you set it to true does it read true. If it does then we know that something else is effectively setting it to false later.

avatar image You! · Jun 19, 2012 at 04:26 PM 0
Share

The Debug.Log shows the animation as enabled...

avatar image whydoidoit · Jun 19, 2012 at 04:28 PM 0
Share

And we know when you logged it before it was false (I'm presu$$anonymous$$g that was somewhere else in the code), so it is getting reset. Hmmm, could try commenting out the Animation.Play lines temporarily to check if it is that.

avatar image You! · Jun 19, 2012 at 05:32 PM 0
Share

...Looking at my code, I now see that the calls for running and the attack are animation.CrossFade()... Should I still comment them out?

avatar image whydoidoit · Jun 19, 2012 at 05:36 PM 0
Share

Yeah Crossfade also fades out the existing animation - but you would expect the existing animation to at least start under those circumstances. Yep, this is quite frustrating... Well comment them out, plus anything that appears to do a Stop(), just so we know...

avatar image You! · Jun 19, 2012 at 05:56 PM 0
Share

Tried it. The running and attack animations stopped, but the throw animation still didn't play...

avatar image whydoidoit · Jun 19, 2012 at 05:57 PM 0
Share

ARGHHHHHH* Which is I'm sure about 1/32 of what you are feeling....

avatar image whydoidoit · Jun 19, 2012 at 05:58 PM 0
Share

Ok maybe there's something up with the Throw animation then - somehow it's stopping before the event, thinks it's finished or something. How about printing the .normalizedTime of animation["Throw"] - it should start at 0 and be 1 when it thinks the animation is finished.

avatar image You! · Jun 19, 2012 at 06:03 PM 0
Share

The noramlized time starts at zero and...stays at zero. I'm calling the debug for this every frame (yay for update!), and the animation is enabled (I still have the debug logs for them showing this).

Edit: I'm trying not to get too frustrated... I gotta keep my P$$anonymous$$A (Positive $$anonymous$$ental Attitude) up!

avatar image whydoidoit · Jun 19, 2012 at 06:06 PM 0
Share

So it is enabled, it's speed is not 0, the normalized time does not change? does the time change? Is somehow this animation ridiculously long - can't be, you'd still see some change i'm sure. Is the weight definitely 1?

I'm just thinking what I know about animations and that is that speed and enabled are the two things that really stop them, I'm trying to remember whether weight = 0 does, but I'm pretty sure that is O$$anonymous$$. If you play through this animation in the animation editor does it appear to work?

avatar image You! · Jun 19, 2012 at 06:21 PM 0
Share

The animation can be played in the animation editor, and the name of the animation is typed correctly when it is called. The speed isn't 0 (its 0.810 as a repeating decimal), and the weight does change to 1. The animation isn't too long (74 frames).

Is there a way to call for the animation using the animation element number? I'm just trying to find a way to call for the same animation in a different way, since it might work then... I don't know, its just an idea...

avatar image whydoidoit · Jun 19, 2012 at 06:24 PM 0
Share

Yeah I see your point. Well you could just iterate over all of the animations and get it that way - it would make sure that there isn't some strange thing going on.

      for(var a : AnimationState in gameObject.animation) {
            ...
      }
avatar image whydoidoit · Jun 19, 2012 at 06:43 PM 0
Share

Sorry I realised I'd typoed and edited it just after I posted. It should be just for( - C# and Javascript are running together in my $$anonymous$$d :(

avatar image You! · Jun 19, 2012 at 07:05 PM 0
Share

This for statement is just a pain... I think I'll stick with the normal way...

Any other ideas?

Edit: Looked at some other question. I'm trying animation.Play().

avatar image Loius · Jun 19, 2012 at 07:29 PM 0
Share

Is 'throw' the ONLY animation playing? Do an animation.stop in your awake/start function and don't play any other animations, see if it plays then. If it does, that means your other animations are probably overriding 'throw' and you need to set its .layer higher/lower (i forget which is more prioritous). I think.

avatar image You! · Jun 19, 2012 at 07:55 PM 0
Share

I already have the layer of the animation set to be 3 (for higher priority), which is higher than the layers for walking and attacking. "Throw" isn't the only animation playing, but it still didn't play when it was the only animation playing (test results shown earlier today in the comments).

Edit: animation.Play didn't work... Any ideas?

avatar image whydoidoit · Jun 20, 2012 at 04:31 PM 0
Share

Just make another animation that does some v simple and replace throw I it to check if it is something specific with the throw animation?

avatar image You! · Jun 20, 2012 at 05:04 PM 0
Share

...I remade a shorter version of the throw animation (44 frames), but still nothing played.

avatar image whydoidoit · Jun 20, 2012 at 05:11 PM 1
Share

This has got to be something to do with the animation oh hell. $$anonymous$$gest you edit your question and put the fact that our investigation has pretty much failed in there in bold :) I can't think what else to suggest...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dylanfries · Jun 29, 2012 at 12:42 PM

Make sure the animation you are calling has a higher blend weight then the animation already playing. If it is lower, the animation will be considered playing but will not have any influence on your model. Also make sure the animation weight is set to 1.0 ( or less if your want to only partially apply it.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Jun 29, 2012 at 12:45 PM 0
Share

Actually the blend weights are normalized and allocated proportionately. A lower blend weight does not mean the animation won't play, it just means it would have a lower effect. Having layers does cause this problem as higher level weights are allocated first.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Children won't animate 2 Answers

Animation.Play blends previous animation 1 Answer

Problem with parent and child animation 1 Answer

Problem Animation Blend 1 Answer

Child Parent problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges