Help needed regarding what is the best for optimization: class with Data being reference by other cl

Dear Community,

I’m a self taughted unity user, having learn a lot from this foruns and from youtube.

I’m making a “simulation game” that is more a deep economical simulation.

Since the beginning I’m trying the best I can learn how to optimize things. I will use a lot of data.

[DOUBT?]

I have a class that represents Industries. Each type of Industry (Farm, Car Factory, Extraction Mine, Refinery, etc.) is a class of their own, inheriting from the class Industries.

My doubt is this, since there will be a big number os objects (industries) I’m placing the data that is common to all industries (a lot of them regarding workers, wages, working environment, levels of proeficiency, methods, etc…) in a Static Class called IndustryData.

Because of that I have been avoiding use some variables in the industries class but place that data in the IndustryData with reference always to that static class.

MY QUESTION IS THIS:
Is this method of placing the data in a public static class being accessed by all objects of the industries classes, or for optimization and cpu performance is best to not to have all objects accessing the lists and arrays in the Static Class but have those values in the object itself?

Thank you a lot for your help.

Optimizing when you don’t have a problem is the definition of wasted engineering effort.

Great question! Sounds complex though, and likely to vary depending if you’re running on a massively powerful gaming PC or running on a five-year-old Android min-spec device. I nominate you to set up the requisite experiments to determine this answer!

Meanwhile, let me just say that you would be AMAZED at how much data a modern computer can crunch. Code your game, if you have a problem, the ONLY way to solve it is to attach the profiler and figure out what’s dogging you down, running on the specific hardware and with the specific dataset that causes you problems.

1 Like

Thank you for your answer.

I’m trying to optimize since the beginning because I’m afraid that I will have to face problems. Graphics will not be the issue because they are minimal, it’s like more a “Spreadsheet”, but the number of calculations I fear they will be to much. I was designing this to Computer and not to mobile. I’m introducing some economic model simulations and agents, representing real countries and economies. For the time being I’m simulating European Economy, but my plan was to expand to US+Mexico+Canada and Asia. I did not have reach that point but things are growing slowly but with a steady pace. And I’m enjoying the process, I’m doing this on my free time.