Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by BlueSin · Mar 07, 2014 at 06:28 PM · 2dgameobjectspriteprocedural

How to handle a MASSIVE amount of game objects?

My team and I are new to Unity, and have been struggling for the last several weeks with one of three problems: either high memory usage or low frame rate or frame rate spikes. We are developing a 2D game (using 3d physics because we are using character controller) that uses procedurally generated maps similar to Terraria and Starbound.

Our smallest map is 4096 blocks wide by 1024 blocks high. For a total of 4,194,304 blocks. Each block game object contains a: SpriteRenderer, box collider, BlockObj script and BlockData script.

Unity will not allow us to create this many blocks on even a small map, much less a large without exploding, so we have implemented chunks to help alleviate the issue. Chunks allow us to set the biome for that chunk, and each chunk will be X blocks wide and X blocks high. Each contain contains a block array, and a box collider (for player entered chunk triggering).

We only load the blocks contained in chunks which either: contain the player, or border a player containing chunk. We implemented a coroutine on block loading to reduce the spikes, but then our frame rate drops while the chunk blocks are loading.

We also have a garbage method which takes chunks that were loaded, and no longer border a player containing chunk and is not a player containing chunk itself. Blocks in the garbage list get destroyed in a coroutine over time.

We poll a special class every 1 second to update player containing chunks, player bordering chunks, and garbage chunks. The system is optimized to not reinstantiate or create duplicates.

With the current system we have excellent memory usage, typcially below 150 MB for a small map. But depending on what settings we tweak whether it be the rate at which we update garbage, player chunks, player bordering chunks (every second), or the rate at which blocks are created/destroyed within their coroutines (0.1f), it just doesn't matter. We either have unacceptable frame rate spikes or frame rate drops over time.

We have tried several other methods in the past as well such as creating faces and turning the blocks into a chunk mesh. This resulted in crazy high memory usage (900+ MB for a small map) but had excellently stable frame rate. We also looked into batching for our current setup and were disappointed to see that the batching is only useful for meshes (which we are obviously no longer using).

I am beginning to think maybe we are doing something wrong. We are new to Unity after all. We need to manage between 4,194,304 and 16,777,216 blocks at a time, in addition to other game objects such as player, flora & fauna, background tiles (for creating that lovely wooden background wall in your house i.e.), environment backgrounds (majestic mountain views!), enemies, NPCs, projectiles, dropped objects, chests, etc. What would be the best way to accomplish this?

Comment
Add comment · Show 2
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 Jamora · Mar 07, 2014 at 07:12 PM 0
Share

Have you considered using Unity's Terrain? You can modify its height and textures during runtime. Unity's terrain is probably more optimized than whatever mesh-combining systems you had. This way the amount of GOs you need to handle would be cut drastically.

avatar image fifthknotch · Mar 07, 2014 at 07:19 PM 0
Share

Destroying GameObjects is somewhat heavy on processing. Try to ins$$anonymous$$d use SetActive. Whenever the player gets too far from the object, disable it so that Unity ignores it. Then re-enable it as the player nears it. Also, if you have pro, Unity's occlusion culling might help as well.

2 Replies

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

Answer by scipiothegreat · Mar 07, 2014 at 11:06 PM

The way most people make voxel games is having each chunk be only one gameobject. The chunk contains (or retrieves) voxel information, then uses that to create a mesh at runtime. So instead of having, say, 16*16 gameobjects per chunk, there is only one gameobject that represents a 16*16 area with a single mesh. This saves a lot when it comes to memory and especially drawcalls. A chunk with one mesh should run much faster and use less memory than a chunk and 256 gameobjects.

For the collision, I'm not sure if you could use a mesh collider. I think it would still be possible to use several box colliders that are turned off when you don't need them.

Also, instead of destroying chunks when they're not in use, you should consider having an object pool and returning the chunk to the pool.

Comment
Add comment · 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
0

Answer by guinoalaskapp · Aug 30, 2021 at 04:21 PM

Yea, but, what if i need to use SpriteRenderers, and some C# lógic for each tile?

And, I use diferent gameObjects cuz of a paralax efect per tile

Comment
Add comment · 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

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

24 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

Related Questions

How to achieve this ? ( pivoting) ! (2D sprite) 0 Answers

How to instantiate a new GameObject (sprite) properly? 1 Answer

2d animation import 1 Answer

Strange renderissues with tiled sprites 1 Answer

how do i make an object always face the player? 5 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