Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Collectible management system

Discussion in 'Scripting' started by Esestor, Aug 19, 2020.

  1. Esestor

    Esestor

    Joined:
    Mar 11, 2017
    Posts:
    3
    So I have a game, in which player must collect certain ammount of collectible items.

    Items will be placed on different levels/locations, and I'm looking for correct approach to handle following rule:
    "item is picked up only once, and will not spawn later unless new game is started, while counter will store number of all collected items during current game attempt".

    As far as I understand, it would be best to have some kind of CollectibleManager GameObject that is able to handle

    a) spawning items on current level if they weren't collected previously
    and
    b) saving/reading data from savefiles on each collectibles's status.

    Main problem - there will be several hundreds of items, and Collectible Manager may become an abomination if it handles ID, position, rotation and bool isCollected for each item.
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @Esestor

    What have you tried so far? = What problem you actually have other than you would like to create such a system?

    I don't think storing information about hundreds of items in JSON or binary save file will be a problem.

    Have a struct or class for item data that has all the fields you want to save. Then when saving, store each item into item data and add those to your SaveData class list which you then serialize as save file.
     
    Last edited: Aug 19, 2020
    Esestor likes this.
  3. Esestor

    Esestor

    Joined:
    Mar 11, 2017
    Posts:
    3
    Thank you, binary save files seem to be the solution to my problem!