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.
I've created a ThirdPersonController, and dropped my model into it. When I hit play, the base character moves and is animated, but the clothes stay in the default position.
The ReadMe for the asset 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 (you'll need to open in a new tab to see the hierarchy properly).
Here is the full AttachToBody.cs script
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 AttachToBody : MonoBehaviour
{
void Start ()
{
int i = 0;
Transform rootParent = transform.root.transform;
GameObject target;
Transform[] bodyBones = null;
for (i = 0; i < rootParent.GetChildCount (); i++)
{
target = rootParent.GetChild (i).gameObject;
if (target.GetComponent<SkinnedMeshRenderer> () != null)
{
bodyBones = target.GetComponent<SkinnedMeshRenderer> ().bones;
break;
}
}
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;
}
}
}
}
So I can determine that the following line is null, but I'm not really sure what target
is or where to go from there.
target.GetComponent<SkinnedMeshRenderer> () != null
Why doesn't my character's outfit animate with the character model?
bodyBones
is null, but how isbodyBones
populated? We'll need to see that code before we can tell you where to place the objects. \$\endgroup\$