Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How would I store lots of data in different scriptable object arrays

Discussion in 'Scripting' started by bebros2, Sep 14, 2022.

  1. bebros2

    bebros2

    Joined:
    Aug 28, 2021
    Posts:
    32
    Hopefully this explanation isn't too confusing. So, I was working on a magazine system where the player could open their inventory and see the magazines for all of their currently equipped guns. The player can change the order that the magazines are loaded into the guns. I currently got this working correctly where the players magazines are instantiated into their different slots. Then if you switch the weapon the magazines are stored in the weapon data scriptable object's array in the order they were put in and the instances are destroyed. But then I realized that you can't store gameobjects then delete their instance since that also deletes the one in the array. So, what would be the best way to go about the storing the multiple magazines and their data (ammo count, max capacity, ammo type, etc.) in a list inside of a scriptable object. Another thing I was thinking about was instantiating the magazines, referencing them, then setting them as inactive and activating them when the gun is equipped. But I feel like that might clutter the hierarchy if I had like 20 guns with 8 magazines each.
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Is there a particular reason that magazines need to be GameObjects or ScriptableObjects at all? Why can't they be regular classes?
     
    bebros2 and Kurt-Dekker like this.