I'm new to Unity but not new to development so I'm wondering what the standard way of doing this in with Unity.

In the scene from the start is an empty GameObject that has a script that contains all of the items in the game. Once the game starts, chest prefabs are going to be spawned in the game and upon interaction they will reveal some random loot from the items script.

Is it better practice to have a script on all of the chests that accesses the items script or should I create another empty GameObject as a sort of a chest manager that accesses the item script and keeps track of all of the chests in the game and what all of their loot is.

  • 1
    \$\begingroup\$ We covered a similar question earlier this year: "Is it more efficient to add scripts to each GameObject or to a single parent object?" The conclusion there was that you can get some runtime efficiency wins from having one central manager script rather than lots of instances. But you may find separating the scripts onto each instance makes it easier to edit them - particularly if you have a team that needs to work on several of them in parallel, so one check-out doesn't lock out other devs. So "better practice" can depend on your situation. \$\endgroup\$ – DMGregory Dec 14 '18 at 19:28
  • 1
    \$\begingroup\$ There's also some coverage of the relative performance impacts of many independent update calls versus one central manager in this previous question about how MonoBehaviour messages work. Do those sources cover what you need to know? If not, can you refine what you're looking for from new answers here? \$\endgroup\$ – DMGregory Dec 14 '18 at 19:33
  • \$\begingroup\$ @DMGregory Oh wow great links! I didn't see those pop up in my searches or I wouldn't have asked this question. I'll close this as that answers my question exactly. Thank you again. \$\endgroup\$ – Mr.Smithyyy Dec 14 '18 at 19:42
  • 1
    \$\begingroup\$ If you like, we could not delete this question and instead close it as a duplicate. That way, folks searching for terms similar to the ones you used will find it in their searches, and get pointed in a useful direction by those links. \$\endgroup\$ – DMGregory Dec 14 '18 at 19:48

Browse other questions tagged or ask your own question.