- Home /
Inventory Instantiation problem
Hi,
I'm using Scriptable objects. My inventory slot script holds an item, let's say a weapon with a specific amount of bullet left. This is done, it works.
When i want to instantiate the item that the inventory slot holds, Unity instantiate a new one. Though i want the item instantiated to be the exact same as the pulic Item field of the inventorySlot (So i can instantiate the same weapon with the same amount of bullet left). To fix that I just say : InventorySlot.Item = itemInstantiated. So i have a reference
But now when the player switched slot with his scrollwheel, i destroy the itemInstantied to instantiate the new one. But since the InventorySlot.Item had a reference to the itemInstantiated well the public field Item says "missing" (normal). So when i wanna scrollback to this slot, obviously it can't instantiate the desired item since there's none anymore.
Question : How can I instantiate an item from the public item field, so both are the same, and when i shoot, it changes the bulletLeft on both the instantiatedItem, and the one the inventorySlot holds. And before I destroy the one in game, cut the reference between both?
If you have a better way of approach, i'm down.
Your answer
![](https://koobas.hobune.stream/wayback/20220613004201im_/https://answers.unity.com/themes/thub/images/avi.jpg)