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

Character customization

Discussion in 'Scripting' started by rycornx, Feb 16, 2019.

  1. rycornx

    rycornx

    Joined:
    Oct 4, 2017
    Posts:
    125
    To have a character customization in my game do you have to have all the model going to be used present on the player pre fab and then just active only the currently used one or is there to script it so you dontnt have to put all on the models and can just spawn the one required unto the correct spot in the rig hierchy?
     
  2. Adamala

    Adamala

    Joined:
    Feb 15, 2019
    Posts:
    17
    If I understand you right, what you can do:
    Add Empty Game Object, then for example, add a Head, Hair, Nose etc. Add a script to Empty Game Object with something like:
    then

    Code (CSharp):
    1. public List<GameObject> Hair; //(add here your different hairs)
    2. public List<GameObject> Nose; //(add here your different noses)
    3. public GameObject mainHair; //(here is your base hair)
    4. public GameObject mainNose; //(here is your base nose)
    5.  
    6. void Start(){
    7.    Customise(0,2);
    8. }
    9.  
    10. void Customise(int hair, int nose){
    11.    mainHair = Hair[hair];
    12.    mainNose = Nose[nose];
    13.    //then if you need it
    14.    mainHair.transform.position = new Vector3(your_x, your_y, your_z);
    15.    mainNose.transform.position = new Vector3(your_x, your_y, your_z);
    16. }
     
  3. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    If your only going to have a limited few options for customization, then having all the objects as children that later are enabled and disabled would be fine - but if you plan on having a lot of options, all those gameobjects might cause some unwanted overhead performance wise. I would instead have an empty gameobject that is the pivot of each customizable part, then instantiate the custom part, and make it a child of the empty. This way there are not tons of disabled gameobjects in the hierarchy of the objects.
     
  4. rycornx

    rycornx

    Joined:
    Oct 4, 2017
    Posts:
    125
    Thanks, these answered the question exactly.
     
    MD_Reptile likes this.
  5. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Good luck!
     
  6. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Like @MD_Reptile said you can do it in so many ways and more, just get to know the tools and get creative ;)
    I would do it exactly like he suggested besides I'd just save the local position of the wanted accessory and use that to cut out another game object(or have an empty and add all the renderers and what not to it in runtime), but I'm a bit extreme when it comes to optimizations, if you don't have a massive project you don't need to stress about it.