How can I modify/change a prefab?

In my game I have a ball (The player) with i want to make skins to. At the moment I’m able to change the material of my prefab player. and the next step is to give the player a hat. I have done research but I’m not able to find the answer!

My player is made out of a GameObject called Player that is the parent to 4 other GameObjects.
The GameObject Player has a Sphere Collider, a Rigidbody and my Player Movement script.
The 4 child GameObjects of my Player GameObject is:

  1. Trail (Not used yet)
  2. Color (Switching between colors via materials)
  3. Face (Not used yet)
  4. Hat (My Problem)

I’m trying to modify my Player prefab so that the user can select a hat that then will go via script and connect a hat prefab and child it under the Hat GameObejct.

My Player Prefab + My TopHat Prefab = Player with TopHat Prefab

The way is want it to work (which i hope is possible) is that using my SkinsMenu. you can choose from an array of pictures (which works) and then you click the button “Choose Hat” then the code should do something like this:

Picture = number

number = hat

give the player hat[number]

If there are missing some information just tell me and I will find and post it!

Thanks for all the help I can get!
Sorry if this is a duplicate (I tried reseaching alot!)

  • Michael
    (First time posting, hope I done it right)

I am not sure if changing the whole prefab is actually what you want/need.

If I understood correctly you just want the gameobject/prefab to change according to the selections made within the skin menu, no?

Shouldn’t it suffice to load a default prefab and simply exchanging the associated hat-model with whatever was chosen within the skin menu in runtime? You’d just need to save the index of the hat-image chosen into a variable and use that index within a script (maybe attached to an object within the prefab) to load the selected hat from your resources.

If I misunderstood anything, just let me know, but from your description this seems like a simple way to achieve what you want.