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 /
  • Help Room /
avatar image
0
Question by Donglecow · Oct 14, 2017 at 03:16 PM · animationcharacter

Character Clothes not Animating with Character Model

I'm very new to Unity. I'm messing around just trying to get my bearings but I'm having trouble getting a character model to animate with the clothes correctly.

This is the asset that I'm using: https://shawarma.assetstore.unity3d.com/en/#!/content/89723

I've created a ThirdPersonController and dropped my model into that. When I hit play, the base character moves and is animated, but the clothes stay in the default position.

The ReadMe says:

Attaching clothing(Classes): Add the "AttachToBody" script to the clothing, the cloths must be inside the character to work.

I believe I have done this but I could be wrong. I have an error in Unity which says

Wrong parent body

Which I can see in the code for the AttachToBody.cs

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

Could somebody help me out and tell me where I'm going wrong please?

I've attached a screenshot for reference.

screenshot

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
1
Best Answer

Answer by Donglecow · Oct 24, 2017 at 02:30 PM

For those interested in the steps I took to fix this, here is what I did based on DMGregory's answer to the same question on Stack Exchange here.

To start with, I created an entirely new character from the same asset.

The hierarchy is:

 ThirdPersonController
 |--  PlayerModel
 |----    CharArmature
 |------      CharBaseM
 |----    WarriorMale
 |------       CharArmature
 |--------       etc...
 |------      TSM_NonSym
 |------      TSM_Sym
 |----    Camera

I created a new script to use instead of the included AttachToBody.cs script, as DMGregory suggested and attached this to ThirdPersonController.PlayerModel.WarriorMale on the WarriorMale object. The new script is below.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 /**
  * This matches the cloth movement to a character, the clothing must be inside the character.
  **/
 public class AttachToMesh : MonoBehaviour
 {
 
     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.GetChildCount(); i++)
         {
             Attachment = transform.GetChild(i).gameObject;
             if (Attachment.GetComponent<SkinnedMeshRenderer>() != null)
             {
                 Attachment.GetComponent<SkinnedMeshRenderer>().bones = bodyBones;
             }
 
         }
     }
 }
  

Which caused the clothes to animate with the player model. I double checked the original script in this position (and descendants) in the hierarchy and was still unable to get it to animate, but when I used the new AttachToMesh.cs script, it worked perfectly, as can be seen in the screenshot below of the idle animation of my player model, rather than the default T-Shape pose.

Animated character

Comment
Add comment · Show 1 · 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 martinfitzjerl · Oct 19, 2018 at 04:42 AM 0
Share

This definitely works, I just tried it. For my case similar deal with two game objects. 1. I had a rig and bare body mesh imported into Unity from Blender. 2. I had a rig and helmet mesh imported into Unity from Blender.

I attached the script to the helmet gameObject (target) and the script worked fine. Be sure to make improvements and adjustments in the script if you feel the need.

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

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

Where i should add some unusual animations in mecanim? 0 Answers

How do I make the Jump Ball rotate in place on the X-Axis? 0 Answers

Unity Rigged Model parts not moving correctly / moving opposite directions with rig (Please Help!) 0 Answers

character animation is not working correctly 0 Answers

How to use humanoid animations for 2d characters? 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