Hello,
I’m building a Unity game which will have a village/town containing potentially hundreds of villagers/peasants. Now if I were to have all of these villagers moving around at the same time I’m sure my PC would blow up under the struggle of having to calculate so much, so I’m trying to think of ways to optimize my game so it runs smoothly. My idea was to have only a certain number of peasants walking around at any one time, and the rest can be “in their house”.
So, my question is, what’s the best way of doing this? Baring in mind, I also want my population to be a proper population, so each day/night cycle I want each peasant to earn a bit of money from their job, pay a percentage towards the towns treasury in tax, and so on. De-activating their objects might save on CPU or GPU performance, but they’d still be taking up RAM so will still have a performance hit, plus their components will be deactivated so it might prevent them from paying into the treasury if I’m relying on co-routines in my scripts or something like that.
I had a few ideas…
- Use de-activation regardless. We could still access the components from an active script, and I assume changing the peasants script variables still works when de-activated. This idea isn’t very good on RAM.
- Save a clone of their object when they go inside a building, and destroy their object. This clone could be re-instantiated at another time. I’m not sure how to do this though, would their variable data like money persist? Does it actually save on RAM if I still have the cloned object? How would I still increase their money overtime if they aren’t instantiated?
- Give up on the idea of having actual villagers, just spawn a random peasant each time and don’t worry about specifics. This would be most performant probably, but it potentially takes away from the actual game in regards to a living & breathing eco-system and economy.
Any help and guidance would be much appreciated.