Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Good way to change character's clothes...

Discussion in 'Editor & General Support' started by BigPowerfulMedia, Jan 18, 2007.

  1. BigPowerfulMedia

    BigPowerfulMedia

    Joined:
    Oct 26, 2006
    Posts:
    20
    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?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    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.
     
  3. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    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.
     
  4. BigPowerfulMedia

    BigPowerfulMedia

    Joined:
    Oct 26, 2006
    Posts:
    20
    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 :p

    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...
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    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.... :D
     
  6. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    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...]
     
  7. BigPowerfulMedia

    BigPowerfulMedia

    Joined:
    Oct 26, 2006
    Posts:
    20
    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.
     
  8. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    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.]
     
  9. BigPowerfulMedia

    BigPowerfulMedia

    Joined:
    Oct 26, 2006
    Posts:
    20
    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! :p 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... :eek:
     
  10. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    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...
     
  11. Talzor

    Talzor

    Joined:
    May 30, 2006
    Posts:
    197
    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.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. //This script copies the location of the body to the head so that the head follows the body.
    6.  
    7. [AddComponentMenu ("Character/Head To Body")]
    8. public class HeadToBody : MonoBehaviour {
    9.     private Transform headI, headII, neckI, neckII;
    10.    
    11.     void Awake () {
    12.         neckI = transform.Find("Face_Neck");
    13.         headI = transform.Find("Face_Neck/Face_Head");
    14.         neckII = transform.Find("Root/Root_ncl1_1/Spine_1/Spine_2/Spine_3/Neck");
    15.         headII = transform.Find("Root/Root_ncl1_1/Spine_1/Spine_2/Spine_3/Neck/Head");
    16.    
    17.         if (!neckI) Debug.LogError(transform.parent.gameObject.name + ": Could not find the head's neck");
    18.         if (!headI) Debug.LogError(transform.parent.gameObject.name + ": Could not find the body's neck");
    19.         if (!neckII) Debug.LogError(transform.parent.gameObject.name + ": Could not find the head's head");
    20.         if (!headII) Debug.LogError(transform.parent.gameObject.name + ": Could not find the body's head");
    21.  
    22.     }
    23.    
    24.     void LateUpdate () {
    25.         neckI.position = neckII.position;  
    26.         neckI.rotation = neckII.rotation;  
    27.        
    28.         headI.position = headII.position;
    29.         headI.rotation = headII.rotation;
    30.     }
    31. }  
    32.  
    33.  
     

    Attached Files:

  12. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    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:

    Code (csharp):
    1. function Init ( userContent : UserInfo ) {
    2.  
    3.     userObj = userContent;
    4.    
    5.     // TURN OFF ALL AVATAR MESH ITEMS
    6.     GameObject.Find ( gameObject.name + "/f_boot" ).GetComponent( MeshRenderer ).enabled = false;
    7.     GameObject.Find ( gameObject.name + "/f_sandal" ).GetComponent( MeshRenderer ).enabled = false;
    8.     GameObject.Find ( gameObject.name + "/f_sneaker" ).GetComponent( MeshRenderer ).enabled = false;
    9.     GameObject.Find ( gameObject.name + "/h_business" ).GetComponent( MeshRenderer ).enabled = false;
    10.     GameObject.Find ( gameObject.name + "/h_buzz" ).GetComponent( MeshRenderer ).enabled = false;
    11.     GameObject.Find ( gameObject.name + "/h_mohawk" ).GetComponent( MeshRenderer ).enabled = false;
    12.     GameObject.Find ( gameObject.name + "/h_spikes" ).GetComponent( MeshRenderer ).enabled = false;
    13.     GameObject.Find ( gameObject.name + "/p_long" ).GetComponent( MeshRenderer ).enabled = false;
    14.     GameObject.Find ( gameObject.name + "/p_short" ).GetComponent( MeshRenderer ).enabled = false;
    15.     GameObject.Find ( gameObject.name + "/s_beat" ).GetComponent( MeshRenderer ).enabled = false;
    16.     GameObject.Find ( gameObject.name + "/s_long" ).GetComponent( MeshRenderer ).enabled = false;
    17.     GameObject.Find ( gameObject.name + "/s_tee" ).GetComponent( MeshRenderer ).enabled = false;
    18.    
    19.     // Apply Attire
    20.     this.applyAttire();
    21.    
    22. }
    23.  
    24.  
    25. function applyAttire () {
    26.    
    27.     if ( userObj.Hair() != null  userObj.Hair() != "" ) {
    28.         GameObject.Find(gameObject.name + "/" + userObj.Hair()).GetComponent(MeshRenderer).enabled = true;
    29.     }
    30.    
    31.     if ( userObj.Pants() != null  userObj.Pants() != "" ) {
    32.         GameObject.Find(gameObject.name + "/" + userObj.Pants()).GetComponent(MeshRenderer).enabled = true;
    33.     }
    34.    
    35.     if ( userObj.Shirt() != null  userObj.Shirt() != "" ) {
    36.         GameObject.Find(gameObject.name + "/" + userObj.Shirt()).GetComponent(MeshRenderer).enabled = true;
    37.     }
    38.    
    39.     if ( userObj.Shoes() != null  userObj.Shoes() != "" ) {
    40.         GameObject.Find(gameObject.name + "/" + userObj.Shoes()).GetComponent(MeshRenderer).enabled = true;
    41.     }
    42.    
    43.     if ( userObj.Glasses() != null  userObj.Glasses() != "" ) {
    44.         GameObject.Find(gameObject.name + "/" + userObj.Glasses()).GetComponent(MeshRenderer).enabled = true;
    45.     }
    46.    
    47.     if ( userObj.Glasses() != null  userObj.Gloves() != "" ) {
    48.         GameObject.Find(gameObject.name + "/" + userObj.Gloves()).GetComponent(MeshRenderer).enabled = true;
    49.     }
    50.    
    51.     if ( userObj.Gloves() != null  userObj.Gloves() != "" ) {
    52.         GameObject.Find(gameObject.name + "/" + userObj.Gloves()).GetComponent(MeshRenderer).enabled = true;
    53.     }
    54.    
    55.     if ( userObj.Hat() != null  userObj.Hat() != "" ) {
    56.         GameObject.Find(gameObject.name + "/" + userObj.Hat()).GetComponent(MeshRenderer).enabled = true;
    57.     }
    58.    
    59.    
    60. }
    61.  
    62.  
    HTH,

    -- Clint
     

    Attached Files:

  13. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    very cool!
     
  14. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    just a small suggestions for halving the amount of code making it run faster.

    Turn this:
    Code (csharp):
    1.  
    2. GameObject.Find ( gameObject.name + "/f_boot" ).GetComponent( MeshRenderer ).enabled = false;
    3.  
    into this:
    Code (csharp):
    1.  
    2. transform.Find(f_boot").GetComponent( MeshRenderer ).enabled = false;
    3.  
    or even better this:
    Code (csharp):
    1.  
    2. transform.Find(f_boot").renderer.enabled = false;
    3.  
     
  15. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Excellent Jo!

    Will do, Thanks,

    -- Clint
     
  16. BigPowerfulMedia

    BigPowerfulMedia

    Joined:
    Oct 26, 2006
    Posts:
    20
    :cry: this forum... *sniff* ...is just so... *sniff*.... beautiful...

    You guys are awesome. Thank you...
     
  17. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    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?
     
  18. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    :D
    Take a look,Find good way
     
  19. Scarro12

    Scarro12

    Joined:
    Jan 18, 2014
    Posts:
    1
    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.
    :D - scarro12