Search Unity

Want to make a dictionary that could be set in the most efficient way

Discussion in 'Scripting' started by Cedrus97, Jul 8, 2020.

  1. Cedrus97

    Cedrus97

    Joined:
    Jul 12, 2019
    Posts:
    18
    I want to have a dictionary of dictionaries that will contain animators. The this is, those are not supposed to ever change so I was hoping that I could make the dictionaries be pre-made or in any other way make them power-efficient.

    If anyone could give me ideas I would very much appreciate it.
    Thanks in advance
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    In terms of power efficiency, as long as you're only writing to the dictionary once over the course of the application lifetime it probably doesn't matter when you create the objects. You will need to do the same amount of work no matter what.
     
  3. Cedrus97

    Cedrus97

    Joined:
    Jul 12, 2019
    Posts:
    18
    True, however, I do not see a reason why I should set the dictionary every time I boot the system. I have no understanding of the subject but it seems like something that would just make the initial booting longer. Is there no way to avoid it?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    If you want to use the data in your program it has to be loaded into memory. There is no way around this. One thing you can do is something called lazy loading where you only load the data into memory when you actually need it. The benefit of this is that if you never end up using the data you don't waste time loading it. The drawback is that if loading is slow you may end up loading at a time that is inconvenient for the user resulting in a bad experience.

    If you only need bits and pieces of the data at a time you can keep it in separate files/assets and only load it in little chunks as needed. It really depends on the nature of your data and your expected access patterns over the course of your game.
     
  5. Cedrus97

    Cedrus97

    Joined:
    Jul 12, 2019
    Posts:
    18
    Thank you for the advice. I will try and see what suits my needs.