Search Unity

Change Character's Appearance

Discussion in 'Getting Started' started by KBurkus, Feb 10, 2015.

  1. KBurkus

    KBurkus

    Joined:
    Feb 1, 2015
    Posts:
    12
    I would like to make a game where you can change your characters appearance.
    For example, in My Talking Tom, you're able to change Tom's clothing when you buy it. I would like to know if/how I would be able to do this.
     
  2. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Model the clothes and rig them to the bone/joints of your character. Import them all in one file so you avoid unnecessary fussing as a noob. Then you create a script that turns each piece on or off. If you have several shirts for example make an array for all shirts and activate only one member of the array whilst deactivating the other members.You can use a button that calls this ChangeShirt function that iterates through the area and does it's business.
     
    TonyLi likes this.
  3. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I actually just started working through this issue myself recently, and ended up going down the route @ippdev suggested. Though since I'm using a single model that will have lots of different hair/face/etc options available, and using that to generate NPCs, I'm starting to slow down and wonder if I'm doing it the best way I can be.

    Anyone know of any good scripts or assets that handle this sort of thing? If not, I'll gladly share mine here once I'm done with it.
     
  4. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    If you are generating NPC's then there is no need to keep the extras. Just Destroy() them.
    Code (JavaScript):
    1. function ChooseShirt (chosenShirt : Transform) {
    2.      for (var  i :int = 0; i < shirts.length; i++) {
    3.           if (shirt[i] != chosenShirt) {
    4.                 Destroy(shirt[i].gameObject);
    5.           }
    6.      }
    7. }
     
  5. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Smart. Thanks for the tip!
     
  6. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,977
    Try this old thread: http://forum.unity3d.com/threads/stitch-multiple-body-parts-into-one-character.16485/#post-202041

    In particular, this post: http://forum.unity3d.com/threads/stitch-multiple-body-parts-into-one-character.16485/#post-866327

    I use the method from that post to do customizable clothing, hair, etc. in my games. I've used it in three games so far without any problems.

    Every clothing object is its own separate object (a prefab), as are the hair objects and a few other other misc. body parts. Using the script from that thread (plus a bit of my own additional code), it all works great. The clothing and hair get attached to the rig at runtime, with animation, etc. and I can add as many more additional items as I wish in the future without having to re-export the entire character rig. It also allows me to keep clothing, hair, etc. in asset packs (Unity Pro) which makes everything even more compact.

    My characters are essentially nude at runtime and then I give them the clothes and hair they need via script. It's very efficient as allows for total customization. I highly recommend this technique. I'm sure there are some improvements to the system that could be made since that thread is from 2010, but I use the code pretty much stock and it still works great. The entire thread is a good read for understanding this stuff.
     
  7. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Ah, yes! Thanks, @Ony! I read that thread a few months ago and I guess I totally disregarded it once I got to work!

    I think the thing that confused me was how to assign the parts to the proper bones in the Armature, but then export it as a separate object and still have things match up. Plus, my plan is to use variables to change colors of parts, too, and I'm clueless about how that would work with merging meshes.

    I'm definitely going to go through and read the entire thread again and see what I can learn.

    Thanks again!
     
    Ony likes this.
  8. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,977
    Just make sure to rig all of your objects to the same skeleton when you set up your skinning (in your 3D program) and then they'll all work.

    I change colors, textures, etc. on my objects even after they are attached at runtime. That's just a matter of addressing the correct material slot in the skinned mesh of the attached object and manipulating colors, etc. as you would any other material via scripting.

    For clarity, when the mesh gets merged to the skeleton, it doesn't actually merge with the original mesh, it just becomes a separate object attached to the same rig and sharing the same animations. So using this technique will not save draw calls at all as the meshes are still separate objects. It's a perfect way to have unlimited customability but it does come with the price of drawcalls. If you're shooting for mobile (I make PC games) then it might not be your best option.
     
  9. NoobFPSDude

    NoobFPSDude

    Joined:
    Feb 25, 2013
    Posts:
    62
    How might someone accomplish this using just textures? Many MMORPGs accomplish appearance changing like armor and clothing, through just painting textures over the model. Many go a step further and add geosets, or deformations of the base model so that clothing variety can be even larger (Why WoW's gloves look bulky and how a character wears a robe) but that's definitely more advanced. Applying extra texture paints is what I'd like to know.
     
  10. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853

    Just repaint the UV mapped texture..if stuff like stains and damage these can be added with a second texture as decals or ovelayed and combined with the original texture map.. The choice button simply loads a new texture into the shaders texture channel and perhaps a normal maps and specular depending on what the garment/armor/object is.
     
    Ony likes this.