[Solved] Character customization question when dealing with multiple models...?

In my current project, the player is able to choose a material for his/her character and I am able to swap out the material using ().material - That is not a problem. However…each character has up to 5 different models as it becomes more powerful (and about 5-6 different materials).

How do I store and set the material for all the other models that replace the original? The models are all created as prefabs, but I have no idea if I am supposed to store something in Playerprefs, somehow update the other prefabs or…? Help would be highly appreciated as I cannot seem to find a workable solution.

You could create one parent per character, and have 5 child models and activate which ever one you need, so the hierarchy looks like this:

YourCharachter
Model1
Model2
Model3
Model4
Model5

Then since you’d know what model you enabled, you’d just change the material on that model using GetComponent().material.

Thanks, but parenting is not what is creating the problem for me. To illustrate:

  1. Player creates a new character. Player selects the model and the material they want.
  2. New game scene is loaded and prefab of the model is loaded as the character. It still has the old material.

So the right prefab is instantiated, but it has the original material and not what the player chose.

I’ve been toying with creating a singleton object that stores the material reference (and possibly other character data) as static variables, but not sure if that is the way to go. Currently, if I do this, the model shows up as a garish pink :confused:

This is what I currently have…
In the script that changes the skin in character generation:

public void ChangeSkinColor(Transform newskin)
    {
        newskin.GetComponentInChildren<SkinnedMeshRenderer>().material = AvailableSkinColours[charmaterial];
        DoDGameMaster.selectedCharSkin = newskin.GetComponentInChildren<SkinnedMeshRenderer>().material;
        charmaterial++;
        if (charmaterial == AvailableSkinColours.Length) charmaterial= 0;
    }

In DODGameMaster.cs I have a public static Material called selectedCharSkin.

In my spawn script, I then have:

if (PlayerPrefs.GetString ("PlayerCharModel") == "CreatureOneHatchling") {
            Instantiate(creatureOneHatchling, characterSpawnPoint.position, Quaternion.identity);
            creatureOneHatchling.GetComponentInChildren<SkinnedMeshRenderer>().material = DoDGameMaster.selectedCharSkin;
        }

And this is where it ends up as pink…

Ok, managed to fix the problem by assigning textures instead of materials. Lot less headaches!!! :slight_smile: