Search Unity

Updating skinning without the model breaking in Unity 2018.3 prefab system

Discussion in 'Prefabs' started by sacb0y, Mar 26, 2019.

  1. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    It's been a long standing issue that updating models with a prefab can cause the model to break to to some issue with the vertext indexing or something.

    I figured 2018.3's new prefab system would solve this since the prefabs seem more nested. But this doesn't seem to be the case, is there a solution for this or not?

    For a project where i may need to regularly update the model due to the complexity of the animation this is a huge problem for me.
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    There are two parts to this.

    First part: Can Unity's model importer detect/guess what objects in a new import of a model correspond to what objects in the previous import of the model, so the same objects in the model stay the same in Unity too even if they have moved in the hierarchy or changed name?

    Second part: Can you edit an imported model, adding components and extra GameObjects to it, and have that still be synced with changes to the imported model?

    The new Prefab system addresses the second part (through using Prefab Variants of Model Prefabs) but doesn't do anything about the first part (since it's not a Prefab issue).

    What specifically is breaking for you and what's your setup?
     
  3. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    The issue isn't adding bones or adding objects, nor reorganizing models.

    It's if i change the bone weights of a model and overwrite the the imported FBX, the model in the prefab will effectively corrupt, so i have to re-add the model to the prefab to fix it.

    So i have my character here
    upload_2019-3-27_11-23-5.png

    If i update the bone skinning and overwrite the FBX file making no other changes, it looks like this.
    upload_2019-3-27_11-24-33.png

    In order to fix this, i have to re-add the model to the scene. Which is absolutely better than before, which would just kill a whole prefab. But it's still not ideal, cause i have to reconfigure and attach a bunch of stuff all over again.

    In some other cases where a model was changed it did act as you state above, in that scenario I needed to re-add the model to the prefab.

    The updated model in this case being the body model, the "eyes" model is unused, it's just there for the "Naomirig" skinned mesh to work. The eyes you see is inside the body mesh, and everything else is using Mesh Assembler.

    It's also worth noting this does not at all affect how it looks in the prefab editor, so the prefab itself in this case is fine.

    upload_2019-3-27_11-34-24.png
     

    Attached Files:

    Last edited: Mar 27, 2019
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Are you saying the model in your assets folder is fine after changing skinning, but the instance of the model in the scene is not?

    When you say you have to "reconfigure and attach a bunch of stuff all over again" what do you mean? Editing and adding components? Do you at any point unpack the instance of the Model Prefab? Because that would surely break the connection and likely produce the results you see.
     
  5. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    yes the instance of the model in the scene is completely broken. So i have to delete the model/prefab from the scene, drag the model/prefab back into the scene to fix it, and then reattach any references to stuff within the prefab, or components needed specifically for that scene.

    And this is just because i updated one skinned mesh within the prefab.

    I'm replacing the prefab with a new instance of itself so i do not use the unpack feature as i'm making no changes to the prefab itself.
     
  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    It's a bit hard for me to understand your setup, but one thing to try out is this: After you've made an edit to the skinning of the model, and you have your broken Prefab instance in your scene, what happens if you click Overrides on the instance and choose Revert All instead of deleting the instance and creating a new one?
     
  7. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    Oh crap i never noticed that overrides menu!

    Yeah that actually seemed to work, AWESOME!

    EDIT: If i had to break down the process

    Import FBX file > nest it in a prefab> bring into scene > adjust bone weights in software > overwrite original FBX file > mesh appears broken
     
    Last edited: Mar 27, 2019
  8. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    Actually no there's still a problem, while that allows for external references, if i for instance have a script under "naomi" that needs to reference objects in the scene that gets cleared...

    It would be more ideal if i could use revert all with the specific model "naomi body" in this case more directly. But i guess it's not a prefab itself exactly so i can't? I don't get the option when that is selected.

    upload_2019-3-27_14-45-30.png

    but even then if i had scripts within that model it would still be an issue.

    So still the issue is that the mesh data for that instance gets screwed up like that...

    EDIT: Oh i see, i went straight to revert all the last time, so i can do it individually, in fact just reverting the skinned mesh renderer seemed to work... hmmm

    Ok that does solve my problem then since i can reset that specific component.
     
    Last edited: Mar 27, 2019
  9. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Great, glad that works! I guess it might be helpful for you to try to find out why the skinned mesh renderer gets modified to begin with (if you didn't do it intentionally yourself).
     
  10. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    @runevision,
    I have the same problem but on prefabs. The skinnedmesh prefab seems to store it's own weight tables/indexes independently from the mesh source and when I change skinning in 3ds max after re-exporting all my prefabs gets destroyed. I have to then spend days setting up characters again. This have been like this since forever. Happens in all Unity versions.
    I just don't get how anyone at Unity don't know or seems to ignore this issue for such a long time? This is very easy to fix, either update the freaking prefab skinned mesh bones reference or don't store it in the prefab (reference them from source mesh directly) as simple as that.
     
    Last edited: Nov 10, 2020
  11. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    Proof:

    As you can see in this video, after re-exporting the skinned mesh, the mesh instance in the scene updates correctly (because is referencing directly the source mesh), however the prefab with skinned mesh gets totally destroyed. Probably cause Unity bakes some mesh data in the prefab and never update it (or does it the wrong way). This in my book is a bug.

    EDIT:
    Furthermore to prove this bug, the mesh on the right is an instance of the mesh (not the prefab) but if I make it a prefab and update the source mesh look what happen:
    upload_2020-11-9_19-34-48.png
     
    Last edited: Nov 10, 2020
  12. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    This should not happen if you make sure to make your Prefabs be Prefab Variants of the Model Prefab. If you don't do this, then yes, this will happen because the Prefab then doesn't reference transform data from the model Prefab but has its own copy which isn't updated when you update the FBX.
     
    tatoforever likes this.
  13. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    Silly me, I'll check if that solves the issue.
     
  14. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,369
    To confirm that making a prefab variant of the mesh solved the issue. I had to redo my character setup (script, references, attachments, anchor, weapons items, etc). As it was an original prefab already before the new prefab system.
    Still I don't get why Unity never updated skinned meshes bones transform when importing a new version of the mesh. It took me like 10 lines of code to fix it myself but this problem is around since forever.
    Anyways, the issue is solved.
    PS: It would be wise to add somewhere in the documentation (or a prompt in the Editor) that tells the user creating Original prefabs of skinnedmeshes will create this problem and suggest the user to make it a prefab variant instead.
     
    Last edited: Nov 13, 2020