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. Dismiss Notice

Replace Avatar in Animator at runtime to create character configurator

Discussion in 'Animation' started by bart_artanim, Oct 6, 2021.

  1. bart_artanim

    bart_artanim

    Joined:
    Jul 18, 2018
    Posts:
    19
    I am working on some character customization. I am currently able to create Avatars from code (via the AvatarBuilder.BuildHumanAvatar API) which have the correct proportions and work fine with Mecanim.

    However, I find that when I create those at runtime and assign them to an existing animator, the new Avatar is not taken into account.

    What I have to do is destroy the Animator component, create a new one, and then assign the new Avatar. What's more, destroying and creating the Animator component cannot happen on the same frame. So I end up destroying, waiting for the next frame, and then continue the rest of my setup.

    There doesn't seem to be anything in the API which could help me out. Rebind() for example sounds like a candidate, but doesn't end up working.

    Is there any way to have an existing Animator understand that it should work using the newly supplied Avatar? I don't even mind if that implies it will restart the current controller/animation.
     
  2. bart_artanim

    bart_artanim

    Joined:
    Jul 18, 2018
    Posts:
    19
  3. ElegantUniverse

    ElegantUniverse

    Joined:
    Sep 13, 2018
    Posts:
    78
    Hi did you find any solution for your issue?
     
  4. bart_artanim

    bart_artanim

    Joined:
    Jul 18, 2018
    Posts:
    19
    Hi. A call to WriteDefaultValues() does update things to a point where the new Avatar is taken into account. So that solves that aspect of the problem. I have not taken that any further however, and I do seem to remember is resets any playing animation. So the change won't be "smooth" as such.
     
    mishakozlov74 likes this.