Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JLJac · Dec 15, 2017 at 12:53 PM · riggingmeshes

How to re-apply a mesh to an armature?

Hi!

I created a rigged character in blender, imported it to unity and applied rigidbodies to the armature to create a ragdoll. So far so good.

In blender, I added another mesh (a clothing layer) attached to the same armature. Upon importing this into Unity, the character in the prefab I already had there is twisted and weird. However, if I simply drag the new model into the scene, it looks good. Because it took a lot of effort to set up the ragdoll, I do not want to apply all the rigidbodies and joints again.

I want to apply the new mesh to the old armature.

Re-coupling a mesh to another armature seems pretty much impossible - no matter what I do the mesh follows the original armature which spawned with it on dragging the asset to the scene. Even if that original armature is deleted!

From my understanding this is because the mesh's Bone Weights are coupled to that armature. How do I change which armature they are hooked up to?

Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JLJac · Dec 15, 2017 at 12:55 PM 0
Share

To clarify, I want Unity to do exactly what it does when pulling a rigged model into the scene, just with an already existing armature.

1 Reply

· Add your reply
  • Sort: 
avatar image
6

Answer by JLJac · Dec 15, 2017 at 01:49 PM

Solved it! Add the below code to a monobehavior. Add the monobehavior to the (same transform as the) SkinnedMeshRenderer. Now drag the base transform of the new armature you want to assign to the Armature slot in the inspector, and click the checkbox to activate the script.

The script will go through the Bones of the mesh, and try to re-assign to bones of the same name in the new armature.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 
 [ExecuteInEditMode]
 public class ReassignBoneWeigthsToNewMesh : MonoBehaviour
 {
     public Transform newArmature;
     public string rootBoneName = "Hips";
     public bool PressToReassign;
 
     void Update()
     {
         if (PressToReassign)
             Reassign();
         PressToReassign = false;
     }
 
     // [ContextMenu("Reassign Bones")]
     public void Reassign()
     {
         if (newArmature == null) {
             Debug.Log("No new armature assigned");
             return;
         }
 
         if (newArmature.Find(rootBoneName) == null) {
             Debug.Log("Root bone not found");
             return;
         }
 
         Debug.Log("Reassingning bones");
         SkinnedMeshRenderer rend = gameObject.GetComponent<SkinnedMeshRenderer>();
         Transform[] bones = rend.bones;
 
         rend.rootBone = newArmature.Find(rootBoneName);
 
         Transform[] children = newArmature.GetComponentsInChildren<Transform>();
 
         for (int i = 0; i < bones.Length; i++)
             for (int a = 0; a < children.Length; a++)
                 if (bones[i].name == children[a].name) {
                     bones[i] = children[a];
                     break;
                 }
 
         rend.bones = bones;
     }
 
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image omi670 · Jun 30, 2020 at 08:47 AM 0
Share

works perfectly! thankyou

avatar image jfonz001 · Aug 02, 2021 at 08:18 PM 0
Share

You rock dude, exactly what I needed. I create a new hair mesh to add to my existing prefabs but they weren't showing up when I dragged them from my base armature to my prefab. This did the trick!!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

74 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I assemble a body from parts in game?? 0 Answers

Disappearing Root on animations 1 Answer

Character Rigging 1 Answer

How do i go about rigging and animating? 1 Answer

Suddenly experiencing problems with imported Carrara animations 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges