Search Unity

Bug Animation clip ignores values

Discussion in 'Animation' started by Its_Gerryz, Aug 27, 2021.

  1. Its_Gerryz

    Its_Gerryz

    Joined:
    Oct 17, 2020
    Posts:
    4
    Whats going on:
    Currently, i'm working on some animations for my project, and i encounter what i believe, appears to be a bug.
    I have an animation clip, (3rd screenshot), where some of the values are on a gameObject (the knife) that gets assigned as a child of the player, during runtime.
    When that specific animation plays, most of the time it ignores the values from that object. I have to mention that the animation plays only when the hierarchy is properly set up, with the player holding the knife.
    Also, i animated that clip, by already having the knife parented to the player, in the editor. Then un-parented it ever since. The values the animation clip ignores are the ones from the knife.
    I think this might be a bug, for two reasons:
    First, right when the knife gets parented even during runtime, the animation values, stop being missing
    Secondly, sometimes it actually works. But on very rare ocasions. Im not aware of doing something that fixes it, it just fixes itself. And on the next play, it doesnt work again.

    Any help is appreciated!
    (enlighten me please xD)




    Here's the clip. You can see the values that are ignored (they are the yellow ones): Delete2.PNG

    And the hierarchy on editor, and on play after the knife is parented:
    Delete.PNG

    Delete1.PNG
     
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Hey,

    I don't think this is a bug. I don't know why, but if the knife object starts separate from the player then Unity doesn't calculate its data or something.

    You can use
    Animator.Rebind()
    after equipping the knife to "refresh" the animator. That should allow the animations to play correctly.

    Let me know how it goes.
     
  3. Its_Gerryz

    Its_Gerryz

    Joined:
    Oct 17, 2020
    Posts:
    4
    actually rebind doesnt work like id like. To be honest it does what i want. after a rebind, the animation plays properly. The problem with that, is that it also snaps all the animation layers to their default states, wich is something i totally dont want. is there a way to stop that from happening?
     
  4. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    I'm sure there's probably a way to accomplish that; unfortunately, I'm not sure how to do it myself.

    Is there any particular reason you can't start with the knife already parented to the player? It looks like you're using the same sprite object for the knife on the ground and the knife that gets equipped, but I think simply deactivating the knife on the floor and activating a player knife would be much easier to manage.
     
  5. Its_Gerryz

    Its_Gerryz

    Joined:
    Oct 17, 2020
    Posts:
    4
    Well, im doing that for testing. In reality, i want the player to be able to hold other items too, in a way that it will be procedual. I will try tho!
     
  6. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    You could have all of the possible items already parented to the player and inactive. Then you just activate the item that is currently equipped.

    It just occurred to me, but if you really want to parent them at runtime, you could animate an empty object and parent the knife to the empty object. That way, the knife will inherit all of the animation, but you won't run into the issue of having to regenerate the animation data.