umasteeringgroup / UMA

Unity Multipurpose Avatar
MIT License
727 stars 167 forks source link

UMA generation fails when switching quickly between different races #332

Closed adrian-j-programmer closed 3 years ago

adrian-j-programmer commented 3 years ago

Describe the bug When using the DynamicCharacterAvatar.ChangeRace to switch between different races quickly, UMAData of the avatar can lose its reference to the generator, causing a runtime error. In addition to that, when switching races, the CharacterUpdated event is not raised, making it impossible to protect the UMA from having its race changed too often.

Environment (please complete the following information):

To Reproduce Steps to reproduce the behavior:

  1. Create a custom UMA race
  2. Create a UI element that implements IPointerEnterHandler interface. Inside the OnPointerEnter function switch the race of your UMA. Have 2 of these elements to switch between the standard male/female and your custom race on hover.
  3. Hover over these UI elements quickly for a while.
  4. Eventually, UMAData validation fails due to a missing generator reference, causing a runtime error.

Expected behavior It should be possible either switch races as often as one wishes to, or to use the CharacterUpdated callback (or other) to programmatically protect UMA from being forced into an invalid state.

Additional context I was not able to reproduce this issue when switching between the default male and female races. My custom race used a custom skeleton, which had to be rebuilt on every race change. When changing between races, I passed on the keepBodyColors and keepDNA flags.

Jaimi commented 3 years ago

This happened because the generation process was in a coroutine, and the skeleton and mesh could get out of sync if rebuilding while it was in the middle of generating somehow. I created new versions of the generator that were not built with coroutines, as well as doing a bunch of null checks. With this new non-coroutine version in place, generation time seems to have improved around 8% in the editor. This will be in 2.11.