Search Unity

Facing problems with Animator State and probably general game design.

Discussion in 'Game Design' started by NikolayPaskulov, Oct 9, 2021.

  1. NikolayPaskulov

    NikolayPaskulov

    Joined:
    Mar 4, 2021
    Posts:
    3
    I will start by telling you guys that I'm kinda new to Unity and game development and design. I'm a .NET Developer for the past 9-10 years and decided to spend this pandemic learning Unity.

    I started really simple as PoC and now refactored everything related to Character Control using StateMachine pattern. I'm using IoC and DI which I saw is not that usual in Unity but I've manage to make it work.

    So at the moment my character can be in one State. After changing state or entering the initial state I'm activating (changing Weight to 1) all Layers related to this functionality.

    I'm using mixamo characters and animations.

    All this last just simple description of my design idea.

    So the problem...
    My character is holding a Bow and I want to disarm this weapon using animation and after that arm sword (for example). I have a Animation Rigging and Multi-Parent Constraint on the Bow. At the right time in Disarm Animation I'm changing the weight of Multi-Parent Constraint to different object but after the change of animation all properties are reset and the Bow is attached to the previous object with different position and rotation.

    I've spend like 1-2 weeks on the problem and read everything that the internet can offer.

    Most likely the problem is my lack of knowledge and experiance with Unity or my design.

    I will appriciate any help or suggestions!
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Are the animator parameters being reset? If so, are you disabling the Animator component? Normally when you disable an Animator component it resets all animator parameters. You can prevent this by setting the Animator's keepAnimatorControllerStateOnDisable to true.
     
  3. NikolayPaskulov

    NikolayPaskulov

    Joined:
    Mar 4, 2021
    Posts:
    3
    @TonyLi Thanks for answering and sorry for the late response.. I tried what you suggested and didn't solve my problem. So I spend the next couple of days changing almost everything that I could and found the problem. Honestly I think it is a bug but as I said my knowledge is limited. The problem is the transition between Disarming the Bow and arming the sword. If there is a Transition Duration (> 0) my Multi-parent Constraint change reset after the animation change.
    Video to show the problem - https://www.dropbox.com/s/urcixehdwjfigw7/Unity.mp4?dl=0
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    What about using animation events to specify the exact frames when the properties should shift between 0 and 1? The values during a non-zero-length transition aren't conducive to a binary "has sword" / "doesn't have sword" state.
     
  5. NikolayPaskulov

    NikolayPaskulov

    Joined:
    Mar 4, 2021
    Posts:
    3
    @TonyLi Just tried this and didn't work. And now it seems really strange that even when I'm setting the weights in the code it is returning to the previous weights. This is how I'm setting the weights:
    bowMultiParentConstraint.data.sourceObjects.SetWeight(0, 0);
    bowMultiParentConstraint.data.sourceObjects.SetWeight(1, 1);