Associate objects to a prefab

This question has probably been asked several times in several different ways. I’m fairly new to Unity, but an experienced coder. My question is best described by an example:

I have a Player : MonoBehaviour object and I’d like to be able to associate it with another MonoBehavior (e.g. sword, helm, etc…). The player object has member variables that will hold the instances of those objects (e.g. ISword, IHelm, etc…) I’m having trouble identifying a pattern for instantiating these peripheral objects. I can either Instantiate(…) the object, but then it must be referenced somewhere in the scene hierarchy beforehand OR I can <>.gameObject.AddComponent(), but this will result in a new instance each time.

The latter would make more sense in this case. However, if I wanted to spawn a sword into the world, it seems like I would need some general container to hold it. I guess, that could be a chest or vendor.

I’m just looking for some general guidance here, I’m sure this has been solved 100 times already.

Thanks ahead of time :slight_smile:

Prefabs and references to them after the project is built are just serialized data representing the prefab at whatever state it was in when referenced(in the inspector).

A lot of times people will use either a GameManager object that has disabled objects ready to instantiate or Object Pools that have a range of hidden and instantiated objects ready for use and they recycle them in and out when needed. The point of assigning in the inspector is to have the cookie cutter for instantiation, if you’re project is on a PC/Mac, you probably won’t feel much pain instantiating on the fly, on mobile this can be come an issue depending on how often you instantiate and the quality of the objects in general.

Other then the object pool, the general idea is to use Prefabs and manipulate then when instantiating/reusing during that particular frame(setting up the game object).