Is anyone familiar with a simple way to have a character’s clothing change? Is the only way to re-instantiate a replacement character wearing the new clothes, or is there any weird “two meshes with some kind of inherit animation” trick to avoid having to build a character for each new set of clothing?
Depends on whether the clothes need to have their own 3D models. Usually you can get away with swapping the texture.
If that won’t work, there should be a way to link the bones of a shirt to the appropriate bones of the character, either through parenting or through scripting. I haven’t worked enough with animation yet to say for sure how, though.
I’d think instantiating the new model would be be fast enough. I notice a lot of games have a “switcharoo” animation to gloss over any hiccups while changing models though. Ratchet Clank and Sly Cooper use this method.
Thank you StarManta and aNTeNNa trEE. I’ve been watching you cats help people on this board for a long time.
StarManta: As you might guess, swapping materials isn’t going to cut it, unfortunately. Although I am now starting to think our characters would be better off nude anyway
aNTeNNa trEE:
One of my concerns is that the character may have some facial morphs applied to it by the user (user customized face - sort of like Linden Lab’s Second Life). Because I’m not sure how the facial morphing is going to be handled yet (hiring OTEE to dev that part), I’m worried that re-instantiating the char would also mean losing those morphs. I wouldn’t worry about this so soon, except that we are talking tech with a company that that makes avatars for other applications, and if we figure this part out early, we’ll know if their clothes will work in our project or not. Also, I think it would be cool for other Unity folks to know how to do such a thing, being as we would all rather be playing in Unity than spending endless days in a 3D app rebuilding characters…
P.s. I get giddy like a tattooed schoolgirl getting feedback from people I’ve been watching on this board for so long…
You could always have the head be a separate, linked object.
“so long”? AT, maybe, but I’ve been using Unity for all of two and a half months…
what about two meshes - one for the character and one for the clothes. then just instantiate the clothes? build them so the clothes fit at key points yada yada…
[edit: posted at the same time…
You could always have the head be a separate, linked object.
same idea…]
StarManta:
I’m not exactly sure how to do that and have the head be a part of my rig or animation anymore. Sorry to sound sort of noobish, but can a separate object be linked to the head bone and link to the existing animations?
Oh, and You’ve posted enough that I’m a fan of you too, despite only being here 2.5 months.
pete:
Your suggestion is exactly what I’m hoping to figure out how to do in this thread. Have you made that work before? Wouldn’t the clothes need to be animated and attached to the character’s null, or does parenting handle that automatically? It seems that would be way too easy.
nope. sorry, i have never tried. might be wrong but i don’t think that simply parenting would do it. maybe you could attach your clothes using weight maps or vertex painting through a script? i’d be interested to hear otee’s thoughts.
[edit: simply parenting would… well you probably could but it’d be too messy with a ton of skeletons and animations.]
I’d like to hear their thoughts as well. If it’s a weightmap script, I hope they post an estimate of how much that’s going to cost too! StarManta’s mentioning of boning the clothes and parenting them to character’s bones sounds clever, and if I don’t hear any more on the subject, I fear I’ll be boning and weightmapping a shirt to find out. It would really suck having to bone/weight hundreds of pieces of clothing by hand, so a script would be pretty valuable… um… I shouldn’t have said that before they quoted me a price on the script… :shock:
lol. get out that check book!
yeah attaching the bones sounds interesting but i’d think you’d still have to have animations for each piece of clothing. 2 outfits, no big deal but a bunch seems like it would get messy (and a lot of work). maybe you could ragdoll your clothes? anyway, gotta run for tonight…
For what it’s worth, this is what we do in GC: Palestine. Our cha’s basically look like the picture, where “MasterMover1” is the object that is animated, “root” is the body rig and Face_Neck is the head rig. We then have a small script on the “MasterMover1”, which copies the position and rotation of the body rig’s “Neck” and “Head” bone to the head rig’s “Face_Neck” and “Face_Head” bone.
using UnityEngine;
using System.Collections;
//This script copies the location of the body to the head so that the head follows the body.
[AddComponentMenu ("Character/Head To Body")]
public class HeadToBody : MonoBehaviour {
private Transform headI, headII, neckI, neckII;
void Awake () {
neckI = transform.Find("Face_Neck");
headI = transform.Find("Face_Neck/Face_Head");
neckII = transform.Find("Root/Root_ncl1_1/Spine_1/Spine_2/Spine_3/Neck");
headII = transform.Find("Root/Root_ncl1_1/Spine_1/Spine_2/Spine_3/Neck/Head");
if (!neckI) Debug.LogError(transform.parent.gameObject.name + ": Could not find the head's neck");
if (!headI) Debug.LogError(transform.parent.gameObject.name + ": Could not find the body's neck");
if (!neckII) Debug.LogError(transform.parent.gameObject.name + ": Could not find the head's head");
if (!headII) Debug.LogError(transform.parent.gameObject.name + ": Could not find the body's head");
}
void LateUpdate () {
neckI.position = neckII.position;
neckI.rotation = neckII.rotation;
headI.position = headII.position;
headI.rotation = headII.rotation;
}
}
We are actually using segmented characters and then hiding/showing Mesh. There is an attached file for the structure. And here is a rough script on some of the logic we are using to control the options:
function Init ( userContent : UserInfo ) {
userObj = userContent;
// TURN OFF ALL AVATAR MESH ITEMS
GameObject.Find ( gameObject.name + "/f_boot" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/f_sandal" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/f_sneaker" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/h_business" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/h_buzz" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/h_mohawk" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/h_spikes" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/p_long" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/p_short" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/s_beat" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/s_long" ).GetComponent( MeshRenderer ).enabled = false;
GameObject.Find ( gameObject.name + "/s_tee" ).GetComponent( MeshRenderer ).enabled = false;
// Apply Attire
this.applyAttire();
}
function applyAttire () {
if ( userObj.Hair() != null userObj.Hair() != "" ) {
GameObject.Find(gameObject.name + "/" + userObj.Hair()).GetComponent(MeshRenderer).enabled = true;
}
if ( userObj.Pants() != null userObj.Pants() != "" ) {
GameObject.Find(gameObject.name + "/" + userObj.Pants()).GetComponent(MeshRenderer).enabled = true;
}
if ( userObj.Shirt() != null userObj.Shirt() != "" ) {
GameObject.Find(gameObject.name + "/" + userObj.Shirt()).GetComponent(MeshRenderer).enabled = true;
}
if ( userObj.Shoes() != null userObj.Shoes() != "" ) {
GameObject.Find(gameObject.name + "/" + userObj.Shoes()).GetComponent(MeshRenderer).enabled = true;
}
if ( userObj.Glasses() != null userObj.Glasses() != "" ) {
GameObject.Find(gameObject.name + "/" + userObj.Glasses()).GetComponent(MeshRenderer).enabled = true;
}
if ( userObj.Glasses() != null userObj.Gloves() != "" ) {
GameObject.Find(gameObject.name + "/" + userObj.Gloves()).GetComponent(MeshRenderer).enabled = true;
}
if ( userObj.Gloves() != null userObj.Gloves() != "" ) {
GameObject.Find(gameObject.name + "/" + userObj.Gloves()).GetComponent(MeshRenderer).enabled = true;
}
if ( userObj.Hat() != null userObj.Hat() != "" ) {
GameObject.Find(gameObject.name + "/" + userObj.Hat()).GetComponent(MeshRenderer).enabled = true;
}
}
HTH,
– Clint
very cool!
just a small suggestions for halving the amount of code making it run faster.
Turn this:
GameObject.Find ( gameObject.name + "/f_boot" ).GetComponent( MeshRenderer ).enabled = false;
into this:
transform.Find(f_boot").GetComponent( MeshRenderer ).enabled = false;
or even better this:
transform.Find(f_boot").renderer.enabled = false;
Excellent Jo!
Will do, Thanks,
– Clint
this forum… sniff …is just so… sniff… beautiful…
You guys are awesome. Thank you…
Looking through old posts…
Is there any way to combine some of these render calls?
If you split a model into all those pieces, aren’t they going to be the equivalent of rendering a lot of 1 piece characters?
:lol:
Take a look,Find good way
Yes, All you should have to do is change the texture by going to the settings of the character unless the clothes has its own character.
- scarro12