Instantiate or DeActivate multiple gameobjects

Hi, i want to make a player that can switch his cloth and etc
I wonder what’s the best way to do it.
I can active the only gameObject that i need but i don’t know if it is a good choise because 100 kind of cloth would be too much to manage or too heavy for the game.
So i tought about instantiating each time i switch.
Changing just the sprite it’s an option too.

it is a 2D game.
Thanks.

I think your question is like this:
what is the best way to change clothes for the character?
a) have all clothes already attached to the player game object and simply activate / deactivate them
b) having no cloth at all on the player character. They are instantiated and attached at runtime
c) having one game object for each kind already attached and simply change the sprites

All three ways are possible. Here are my thoughts about it:

a)
This is probably the fastest way to change the cloths. The huge number of game objects shouldn’t really affect the performance of the game, because unity doesn’t spend much (maybe not even any) resources on inactive game objects.
However, I guess the loading time will increase, because all objects need to be loaded on start. In addition it needs more memory. Also, it probably will be a bit messy in the hierarchy…

b)
Instantiating objects at runtime has a performance impact. You should not do this often during play because it can decrease your frame rate a bit. However, I believe that you would instantiate the cloth objects only during load of a level, where it is normal that the player has to wait a bit. Also you might have a little “Editor” where players can select the cloths they want. Destroying one old and instantiating one new game object when the player presses a button is totally fine. Nobody will notice.
So, if I am right with my suggestions, this solution is totally okay.

c)
changing sprites is probably much faster than b). The question is how you manage all the sprites. If you only change the sprites you will also be restricted because every cloth must follow the same criteria (size, animation steps, …). So, this is probably not the best solution. It is not very flexible and hard to manage.

Conclusion: I would go for b). Here you have the most flexibility and no need to manage a huge hierarchy of objects.

Thanks man, really appreciate the comment!
Btw, to use that method i should make an array and drag and drop all the cloth?
That would take time too no?

Not sure what you are asking… The time to assign all cloth you need to do or the loading time of the program…?

for both there would be a solution how it would be pretty fast:
Create a folder called Resources and Subfolders for each kind of cloth. Place your respective prefabs in those sub folders. Now you can load them via Resources.Load() and get a list of all of them via System.IO. This way you just need to place new cloth in the right folder and it is integrated in the app automagically.

That work for mobile too?

yes

I don’t understand how it works.

public GameObject tmp;

void Start(){
tmp = Resources.Load("Hairtry", typeof(GameObject)) as GameObject;
}

i tryed this

that is the first part. With that code you are loading the prefab into memory. Now you have to instantiate the prefab:

    public GameObject tmp;
    
    void Start()
    {
        var prefab = Resources.Load<GameObject>("Hairtry");
        tmp = GameObject.Instantiate(); // you can also pass a parent here
    }