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.
Thanks, but parenting is not what is creating the problem for me. To illustrate:
Player creates a new character. Player selects the model and the material they want.
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
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.