Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 DedWnutry · Apr 23 at 01:47 AM · animationsequipment

How to make cloth follow the character movement?

So I created Player character in Blender, add him rig, make it animate. Then i made bracelet in the same blender file, attach it model to the character's skeleton and export like FBX-file. In Unity bracelet prefab parented to the character model. For now bracelet follows player's position when he moves, but not animate with him. So when player moves, his parts animating, but bracelet don't go with forearm. In blender when i move forearm, it's follows properly, so fbx was made fine. I googled this problem and find kinda solution for this. Here's script i found:

 void Start()
 {
     int i = 0;
     Transform rootParent = transform.root.transform;
     GameObject target;
     Transform[] bodyBones = null;
     var skinnedMesh = transform.parent.GetComponentInChildren<SkinnedMeshRenderer>();
     if (skinnedMesh != null)
     {
         bodyBones = skinnedMesh.bones;
     }

     if (bodyBones == null)
     {
         Debug.LogError("Wrong parent body.");
         return;
     }

     GameObject Attachment;

     for (i = 0; i < transform.childCount; i++)
     {
         Attachment = transform.GetChild(i).gameObject;
         if (Attachment.GetComponent<SkinnedMeshRenderer>() != null)
         {
             Attachment.GetComponent<SkinnedMeshRenderer>().bones = bodyBones;
         }

     }
 }

}

As i understand, this supposed to replace one of the bones of character's skeleton with one, that uses my bracelet prefab. But it didn't work for me as well. No errors, no massages from the script about not finding target bones. Both character mesh (named "Body") and the brcelet model has Skinned mesh attached to it. The script is on bracelet. When script attached to anithing else, bracelet mesh just dissapears or goes inside character's mesh and becomes very small (literally like 0.1 scale) and places in wrong angle. I can't find out where i'm do it wrong. Maybe, it's about poor hierarchy or smth. Please, help, i struggling with this almost whole week. alt text Sorry for bad English :|

hierarchy.png (64.9 kB)
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 DedWnutry · Apr 26 at 10:03 AM

I finally found the solution by myself somehow! It's very simple, litterally just 2 lines of code. All you need is write in AttachToBody script:

 public GameObject target;

 void Start()
 {
     gameObject.GetComponent<SkinnedMeshRenderer>().bones = target.GetComponent<SkinnedMeshRenderer>().bones;

     gameObject.GetComponent<SkinnedMeshRenderer>().rootBone = target.GetComponent<SkinnedMeshRenderer>().rootBone;
 }

And that's all! This replaces replaces your object rootbone and bones with targer's. Attach this script to the cloth object, parent it to player's model and drag Body mesh in target slot in inspector. Maybe it currently works only in one direction and you can't unequip item, but for now this all i was needed.

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

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

141 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

Related Questions

Animations Can't Be Execute 0 Answers

Root motion makes my character unable to turn. 1 Answer

Parent animator controller overrides child's animations 1 Answer

Mixamo Animations 1 Answer

Unity Animator cant play the same animation twice. 2 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