The best way to manage equipment in RPG ?

Hi !

I'm currently working on the inventory of my RPG. I can drag a piece of equipment on my character (that's already done), and I want that object, let's say gloves for instance, to be displayed on my character in the scene.

So here is my workflow : once the gloves are dropped on my character, I instantiate the prefab which contain the mesh, the same animations than the character (same bones, at least those that are needed, etc), and the script that animate all that. Finally, I make it child of the character. But let's the code talk for me, it will probably be easier ;)

// Gloves have been drag from the bag and dropped onto the character
// they are removed from the bag, now they are created in the scene
var pref = Resources.Load( "animatedGloves" );    
var instance = GameObject.Instantiate( pref, character.transform.position, character.transform.rotation );
instance.transform.parent = character.transform;

So, here is my question : Is using Resources.Load int the middle of the game, probably quite often, a good way ? I'm afraid of the cost :(

I could store the prefab in the items I put in the level, but once I pick them up and store them into my inventory, I Destroy() them, thus I’d loose the prefab.

Resources.Load is expensive. Use at your own peril.

With the instance destruction, you are close, but not quite correct. You don't lose the prefab, but rather all references to it. As long as there is some instance of the asset referenced somewhere in the scene, it is built into the program. Even an instance of a prefab in a script (not necessarily `Instantiate`d in the scene). You can destroy the pick-up instance as long as you store a reference to its prefab (not the pick-up instance) somewhere that you can get it from later.

One mechanism is to store a reference to the prefab within it's instances (convoluted much?). Something like storing a reference (index) to the instance stored in some grand items array object which keeps references to all of the pick-ups' prefabs. Then, when you pick up the prefab, you merely pass along this reference to your inventory script.

There are other ways to go about it, but again, the idea is to keep a reference to the prefab somewhere and not lose it. How you go about that is up to you.