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 N00MKRAD · Sep 11, 2017 at 06:59 AM · performancegenerationcullinginfinitemany

What's the best way of handling hundreds of objects in an infinite world without killing the framerate?

So, I have an infinite level generator set up.

It basically instantiates tiles (floor + some models on it).

My render/shadow/AO distance is already at around 60, so GPU load is no big problem.

However, it seems having a high amount of objects in general can cause the framerate to go down (noticed that after flying through my world for a while).

All distant objects are still active (because I'm not sure if disabling them might require more performance than leaving them active), they don't have scripts, but they do affect framerate as the world gets bigger.

Should I apply LOD to every single object? Does culling even affect CPU performance since it's outside of the clipping plane anyway? Should I disable the meshes when they are far away using triggers?

Thanks in advance.

Comment
Add comment · Show 6
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 bobisgod234 · Sep 11, 2017 at 07:29 AM 0
Share

Is your level generator deter$$anonymous$$istic? If so, you can destroy the distant parts of the world as they are not needed, and just re-generate them if you come back.

If your level generator is not deter$$anonymous$$istic, or the world may otherwise change in unpredictable ways (e.g. player construction and $$anonymous$$ing), then you can try saving the distant portions of the world to disk and deleting them, and loading them from disk when needed.

avatar image N00MKRAD bobisgod234 · Sep 11, 2017 at 07:36 AM 0
Share

Well, currently the world is static, but a "non-euclidean" level would actually be a nice twist.

So yeah, that's an option, but how CPU heavy is destroying? In my case, around 5-10 tiles each containing 5-10 meshes would get destroyed in one frame, I hope that doesn't result in a spike.

Also, how would it detect the distance? I guess the most efficient way would be a trigger, and when the player leaves the trigger it gets destroyed.

EDIT: Frametime spikes are my main concern, RA$$anonymous$$ is no problem. The player would need to spend days walking around to even hit 500 $$anonymous$$B.

What do you think?

avatar image bobisgod234 N00MKRAD · Sep 11, 2017 at 07:46 AM 1
Share

There is no need to destroy everything all at once, spread it out over time. If you 100 world pieces that suddenly become a candidate for deletion, add them to a list and destroy them only a few at a time.

There would be many ways to get the distance. You can use trigger zones, but be careful when setting this up - having many overlapping trigger zones that are configured to trigger each other (e.g. by being on the same layer) can cripple performance very easily.

You can also do a simple distance check to the camera. You can set this up similarly to how the above destroy works, only checking a small number per-frame to keep performance good regardless of the number of objects.

Show more comments
avatar image Cherno · Sep 11, 2017 at 09:36 AM 1
Share

Are all your tiles seperate gameobjects? If yes, then that's very bad. Use chunks ins$$anonymous$$d and combine tiles into one mesh per chunk, and make each chunk as large as the vertex limit allows.

avatar image N00MKRAD Cherno · Sep 11, 2017 at 11:07 AM 0
Share

They are separate GOs indeed...

I'll look into combining as much as possible.

I don't know if I can combine the props (every tile has a random set of props) but at the very least I can make the floor huge and not per-tile.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by joelybahh · Sep 11, 2017 at 11:42 AM

@N00MKRAD Disabling them will most likely benefit frame rate from my experience. also using LODS for all your procedural content will help drastically!

Occlusion Culling will definitely help! however, that may require some custom code on your front because unity by default simply bakes in the culling, so any procedural landscape will require your own implementation!

And yes! I have run tests before and culling does do wonders on performance, especially in dense areas of shrubbery.

A simple method could be to simply use the Vector3.Distance, and set a distance threshold that when exceeded, disables the distant object if(Vector3.Distance(player.position, terrainChunk.position) > DistThreshold) terrainChunk.SetActive(false); however better methods are no doubt floating around google!

I hope I have helped you out a little, but long story short, yes disabling the objects far away will definitely benefit performance in a good way! if you need any more help feel free to reply :)

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 N00MKRAD · Sep 11, 2017 at 12:04 PM 0
Share

Well, keep in $$anonymous$$d that they are not rendered anyway. Does disabling (Or Occlusion Culling or LOD) still help, even if they are behind the cam's clipping plane?

I mean, they aren't rendered anyway.

And isn't it kinda expensive to calculate the distance to the player on thousands of objects?

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

90 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

Related Questions

Random Terrain plus features generation 1 Answer

Can the Cull option in shader improve perfomances ? 2 Answers

Terrain.CullAllTerrains() Performance 0 Answers

Sprite shape culling performance 1 Answer

LOD not improving performance as much as it should, see profiler screenshots 0 Answers


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