Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 saiverx · Apr 30, 2018 at 09:20 PM · animationarraybonesskinnedmeshrendererclothes

Bones do not switch when called for (Find bones of player then replace clothes bones)

Hello! I have an issue with my script where as the bones that i assign and the bones that i get do not replace.

Basically my script is designed to replace the bones inside of specific clothing, in order to fit on my character. So the script gets all the bones from the skinned-meshrenderer of the clothe, finds all the bones inside of the player and then attempts to replace the bones assigned to the clothe with the playerbones, thus making the cloth act upon the player-bones. My issue is that after the all the bones have been found (both inside the clothe and the player), none of the bones are replaced. I'm not too sure what I am doing wrong as I have tested a previous script where this worked almost perfectly. My issue with the previous script is that the clothing that I want to use, uses multiple bones from my character. That script only let you assing one skinnedmeshrenderer (in my case, I have multiple skinnedmeshrenderers for my characters body), therefore making it not find the correct bones or leaving it with missing bones.

Here is my code:

 void Start()
     {
         GameObject playerBones = GameObject.Find("ThirdPersonCharacter/Male/Male");     // Find the Parent of the bones
         Transform[] allChildren = playerBones.GetComponentsInChildren<Transform>();         // Get a list of all the children from the parent
 
         print("Object: " + playerBones);                                                                                // Displays which gameobject the script found
 
         Dictionary<string, Transform> playerboneMap = new Dictionary<string, Transform>();  //Creates a dictionary for the bones
         foreach (Transform child in allChildren)
         {
             playerboneMap[child.name] = child;
         }
 
         SkinnedMeshRenderer thisRenderer = GetComponent<SkinnedMeshRenderer>();
         Transform[] boneArray = thisRenderer.bones;
         for (int idx = 0; idx < boneArray.Length; ++idx)  //this checks if the bones match up, debugs an error if a bone is missing
         {
             string boneName = boneArray[idx].name;
             if (false == playerboneMap.TryGetValue(boneName, out boneArray[idx]))
             {
                 Debug.LogError("failed to get bone: " + boneName);
                 Debug.Break();
             }
         }
         thisRenderer.bones = boneArray; //take effect and replace the previous bones with the playerbones
 
 
         // Debugging, this will display all the children of the parent (the bones of the player)
         foreach (KeyValuePair<string, Transform> bone in playerboneMap)
         {
             print("Bone: " + bone.Key);
         }
     }

I really hope someone can help me out with this issue, as it will greatly increase my work on this game. :)

Thanks in advance!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by saiverx · May 01, 2018 at 01:14 AM

Something to add is that I have looked around on this forum for some similar results, yet no post has solved this issue. My code is based of one of the answers from this post

Yet I do believe that the error resolves around the thisRenderer.bones = boneArray; //take effect and replace the previous bones with the playerbones-part. But I'm not sure how I can assign the bones in any other way?

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 Cherno · May 01, 2018 at 10:32 AM 1
Share

Do all the clothing mesh's bones have a weight associated with them, even if it's 0? Bones with no weight (not 0, but none at all) will not be inclded when you export your mesh. This issue is detailed in the link you posted.

avatar image saiverx Cherno · May 01, 2018 at 12:43 PM 0
Share

Hi, Cherno! Yes my bones do have a weight associated with them (both my playermodel and the clothing mesh). I am using the exact same rig/bones from my player on the clothes. So in theory there should not be a problem replacing the existing bones in the clothing mesh with the player-bones. Thank you for your suggestion! I will look at bit further into this and see if maybe I have done something wrong.

::EDIT:: https://imgur.com/a/DY61Qvq Here you can see both the models and rigs in 3ds max, with bone-weights.

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

228 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get the initial bone positions for a skinned mesh 0 Answers

What space are the bones from an armature and the vertices of a mesh in? 1 Answer

Is it possible to update a skinned mesh renderer's bones? 1 Answer

How can I get the original bone bind position ( and not the matrix)? 1 Answer

Transfer bones from one Object to another (same meshes) 0 Answers


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