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 /
  • Help Room /
avatar image
1
Question by Colajojo · Aug 16, 2016 at 06:04 PM · c#instantiatespawnlagfreezing

What is the most efficient way to spawn in a lot of cubes, like 10k? [c#]

Ok, so i've been testing to spawn in a lot of cubes, in a grid way(50x50 or 100x100) but the issue is that it freezes the Unity Editor for a long time, when i spawn in a huge amount of cubes. At the moment im using the primitive cubes that Unity comes with, and i spawn them in one time, all of them at the start.

Im wondering is there any better ways to instantiate cubes in a huge amount? Like should i instantiate small chunks until it reaches the goal of amount of tiles i want?

So if im able to fix the first issue, and im able to make a huge grid of cubes in faster way, then im think im gonna have two new issues.

First one is that if i were able to do 200x200 then it would mean 40000 cubes/object to check for in a loop. How would i be able to loop through so many objects, without big performance issues?

Then the other one is the graphical part, where 200x200 cubes would may lag the game, fps wise.

Update: Below is a 75x75 grid of cubes, every tile here is one cube, and all the cubes will be viewed from above, so i've would want to achieve something like this, but cheaper, faster and pleasant for the computer

alt text

d874f87607600362ba6a3ea3e97fdcfa.png (223.8 kB)
Comment
Add comment · Show 4
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 tanoshimi · Aug 16, 2016 at 06:09 PM 0
Share

Why do you need 10,000 individual cubes?

avatar image Colajojo tanoshimi · Aug 16, 2016 at 07:31 PM 0
Share

As i said, i would want to make a grid of cubes. Since im atm working on making a procedual map generator.

avatar image tanoshimi Colajojo · Aug 16, 2016 at 07:38 PM 0
Share

But why do they need to be individual cubes? Is there a possibility of seeing all 6 sides of every cube?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by CausticLasagne · Aug 16, 2016 at 06:21 PM

It depends on what you're using them for. I've tried doing this for a minecraft type game, and it does not work.

I used a loop to create the level and it didn't work very well. I have a game in development that uses lots of cubes as a core game mechanic, and I use Occlusion to hide the cubes not visible to the camera.

Spawning lots of cubes with Rigidbodies will fry your computer. if you want to mass spawn cubes, the less components assigned to them, the better. I'd even make them static to lower the memory.

If I knew more about what you're trying to achieve, I can help you more.

  • Causticlasagne.

Comment
Add comment · Show 3 · 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 Colajojo · Aug 16, 2016 at 07:50 PM 0
Share

I wrote that i want a grid of cubes, so here is more info of the process of creating them.So i start off by making a noise map, then take the noise map and make the properties for the cube, then i instantiate the cube with it's properties. I take the noise map once, and then make a for-loop and generate all the cubes i want.

It takes like 1 second to just create all 100x100 objects alone, but it's the creating the and visualizing the cubes that create lag and freezing the computer.

I've looked at Task $$anonymous$$anager when it freeze and it doesn't consume all CPU or the $$anonymous$$emory

avatar image CausticLasagne · Aug 16, 2016 at 08:18 PM 0
Share

Well either way, even if you want a grid of cubes, and the player is looking at them right? You should only be drawing 3 surfaces at a time. And if you're making a terrain generator out of cubes similar to $$anonymous$$ecraft, you want to cull faces that are not visible to the player. Doug has the right idea. Though I've seen an example where a group of faces are chunked into a single mesh and each mesh is then generated. It's still single cubes, you just need to remove a cube from the mesh. The only issue that is causing the lagg is the rendering of each face on the cube. If you are only drawing 3 faces on each cube + only the faces that are visible, then you'll be able to make more cubes/chunks.

CausticLasagne

avatar image CausticLasagne · Aug 16, 2016 at 09:28 PM 0
Share

So you are making a terrain. Okay. For this you'll need to group some cubes into a mesh, say 8x8 cubes, to form a chunk. This chunk will have it's own collider. On your chunk prefab, you'll need to create a script indexing the cubes that are present and their material id's.... and so on. The tricky part is syncing each chunk so you have a nice even terrain. I'm not personally working on a project like this at the moment, though I can point you in the right direction. Look at this package for info about chunking. Import the project and mess around with some settings.

There is also some fun stuff happening at Volumes of Fun, and they're experimenting with The $$anonymous$$arching Cubes Algorithm, which I'm not sure is up your alley.

Cubinquity For Unity

Polyvox

Take a look at some of these things to get a hint on which direction to go, but they all use the crap I'm going on about. Be aware that it does require some understanding of mathematics to make a good cube based game, and with marching cubes involved...... That's why I gave up.

I hope I've pointed you in the right direction.

CausticLasagne

avatar image
0

Answer by DougMcFarlane · Aug 16, 2016 at 08:09 PM

For simple cubes, creating dynamic vertices and triangles would be the quickest, and require the least resources. It would be faster to render too. You should chunk together multiple cubes into multiple game objects, Minecraft style. Having them all as one model containing every cube may start to push the limits.

Chunking would be your best bet, but testing to find the best chunk size would be needed. A 8 x 8 x 8 cube object sounds like a good start. Chunking would allow for occlusion, so it wouldn't have to draw every cube every frame. If you need each cube to have a collider, you can add multiple cube colliders to the game object to make a larger compound collider.

You could still color each cube differently if you use vertex colors in you shader. You could use arrays to hold each cube's attributes (color, size, visible, etc) and have a routine to regenerate a new chunk if any of the cube data changes.

Comment
Add comment · Show 3 · 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 DougMcFarlane · Aug 16, 2016 at 08:22 PM 0
Share

I had assumed literally the OP wanted individual cubes, each separated by a certain distance. $$anonymous$$nowing you are trying to replicate $$anonymous$$inecraft style graphics, this is a bit different. You would still create vertices and faces per cube, but can eli$$anonymous$$ate any faces not exposed. Especially for cubes that are completely surrounded which would have no faces.

avatar image CausticLasagne · Aug 16, 2016 at 08:27 PM 0
Share

I don't understand what the OP wants exactly. Sure he wants 10k cubes, but what for? Terrain Gen? Shits and giggles? If these cubes are rendered on a camera, then only 3 faces need to be visible, and also the faces that are obscured by other cubes.

avatar image Colajojo · Aug 16, 2016 at 09:06 PM 0
Share

If you would check out the update up there, you might understand what type of graphics style im trying to achieve, and i what you wrote, what i've understand i would make a chunk that has it's own created mesh(Procedual ofc) and then somewhat link them up?

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

7 People are following this question.

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

Related Questions

Make a collision check when spawning with Instantiate 1 Answer

Instantiate spawn problem 1 Answer

Help with Instantiation and Sprite changing lag 0 Answers

Spawn a random object on more than one position 1 Answer

Spawn enemies so they aren't instantiated on top of each other (C#) 2 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