Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by wooolly · May 04, 2020 at 07:18 AM · performance optimizationclonecharactersrampersist

Best way to have lots of villagers

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by logicandchaos · May 04, 2020 at 08:21 AM

Well the main thing you want to do, which you haven't mentioned, so not sure if you are doing it yet, is to make sure you don't have an update on your villagers.. You need a Villager Manager. If your villagers make the same money and pay the same taxes then you don't need to do a the calculations over and over again, you just do it once and then times it by the number of villagers. if they make and pay different amounts then you will have to do more calculations, but you still want them to all be happening in one update. So if you have Update() in your villager script, then rename it VillagerUpdate and add it to the VillagerManager Update(). Lucky for you I have a free asset for doing this very thing https://assetstore.unity.com/packages/tools/integration/update-loop-manager-163728 I do something similar in my RTS asset and that allows me to move direct over 300 troops smoothly.

Destroying and reinstantuating is always the more processor heavy option, if you are going to use something again better to just deactivate it. When trying to create a living & breathing eco-system you will have to use some smoke and mirrors. LIke in a game where you earn money even when it's not open, it's not running in the background or a cloud it just takes the current time and the time you last logged in and calculates the amount. As long as the math is right it doesn't matter, you want to get the same result with less effort.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wooolly · May 04, 2020 at 12:39 PM 0
Share

Hey LogicAndChaos, thanks for the response. It's always great hearing about how others might do things, and I really like your idea of using a $$anonymous$$anager to update everything at once in a single location - this is good because even if the peasants are deactivated, the code still runs! As for the deactivation or destroy, I see what you mean and I agree many re-instantiations is probably more costly than just keeping objects alive in RA$$anonymous$$ to be re-used at a later date. I think I've got a way forward now, and it's using what you've recommended, thanks.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

127 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Project moved to Unity 2020 from 2017 using much less ram, less CPU, but performing much worse 0 Answers

Skinned mesh performance concerns 0 Answers

Cloned object has not materials/textures 0 Answers

how to improve the the colliding system 2 Answers

How would I enable a particle system based on size/magnitude? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges