Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Oct 19, 2011 at 12:24 AM by CarlLawl for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by CarlLawl · Oct 16, 2011 at 08:51 AM · chunks

Question about "Chunks"

Hey I'm having a little trouble with "Chunks" I understand how they work logically but I can't for the life of me figure out how to put it into practice programmatically. I've checked out a few examples but I'm still quite stuck so I thought I'd see if anyone on here could maybe write up some pseudo code and explain it a bit.

Thanks in advance everyone, Carl

Comment
Add comment · Show 5
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 syclamoth · Oct 16, 2011 at 11:21 AM 1
Share

Explain 'Chunks'. I'm not sure what you're trying to do here! Are we talking $$anonymous$$inecraft here? Or does it mean something else? I think you would do that kind of thing with LoadLevelAdditively, but you might not (depending on how it works).

avatar image CarlLawl · Oct 16, 2011 at 02:04 PM 0
Share

Sorry I should have been clearer, apologies. Yes similar to $$anonymous$$ecraft, where the level is split up into "Chunks" sections, it's similar to Octrees (Which I also can't wrap my head around programmatically) http://en.wikipedia.org/wiki/Octree

So if I had my terrain generated already how would I split it up into chunks or would I have to do as part of the generation process?

Thanks, Carl

avatar image syclamoth · Oct 16, 2011 at 03:32 PM 1
Share

Octrees are fantastic, although yeah, hard to program if you can't get your head around them.

You should split your terrain up into chunks when you generate it, and then manually load the ones you want when they become relevant. There are a lot of ways of doing this, and as I said before, it really depends on exactly what your application is.

avatar image CarlLawl · Oct 16, 2011 at 04:02 PM 1
Share

Well I'm going to try for something similar to $$anonymous$$ecraft as it seems the easiest thing to practice and learn with.

Lets say I was to generate 64x64x128 set of primitives to then divide up into 4 16x16x128 chunks, and to keep it simple just iterated through 3 loops instantiating a primitive to get a cube of cubes (not worrying about vertices, triangles etc)

for (int x = 0; x < 64; x++) { for (int y = 0; y < 128; y++) { for (int z = 0; z < 64; z++) { // intantiate primitive at x,y,z } } }

How would I go about slicing it into chunks? Or would you recommend doing it a different way? I'm not trying to make a full game I'm just trying to broaden my knowledge and learn efficient methods

Thanks, Carl

(It wouldn't let me format the code in a comment)

avatar image CarlLawl · Oct 16, 2011 at 11:33 PM 0
Share

Ok so after so more researching I've managed to work out octrees to a degree but I'm still stuck with "Chunks" and indexing them

1 Reply

  • Sort: 
avatar image
0

Answer by DavidDebnar · Oct 17, 2011 at 09:10 PM

Minecraft is really advanced stuff but the basics are quite simple. Notch generates few perlin noises and uses them as density map and height map and some other ones. Then he iterates trough the pixels of the noise and splits it into "chunks". If you want good optimization and you are working on a minecraft like game than a 32x32x128 chunk has really good performance. So you iterate trough the noise and at every 32 pixel just split it into another chunk. Also one chunk is one mesh. So you have to add sides, yes sides not cubes, to it, and check if the side can be seen, so you don't waste ram. Chunks are good for not having the whole world in ram at once.

Short: World is made of chunks. Chunks are made of faces that make cubes. Chunks are parts of noise. Don't use instantiate it will kill your PC/MAC, instead use the Mesh class and generate meshes manually.

Also, take a look at MinePackage. It is a really nice terrain generation algorithm made in unity, and you can download the source code.

Edit: I read your coment about "indexing the chunks". If you want to save it, just save the noise and the changed cubes instead of whole meshes and generate the world again and again on each run from the noise + changed cubes.

  • David

Comment
Add comment · Show 2 · 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 CarlLawl · Oct 18, 2011 at 05:36 PM 0
Share

Thank you for the reply dzebna, I knew most of that already but I appreciate you taking the time to reply and im sure itll help others

I was looking at $$anonymous$$inePackage but it's quite complicated to break down, I'm getting there I just wondered if anyone else could explain how to go about splitting into chunks, programmatically anyway

So just make another int and in the z loop just increment it by one if its 32 create a new chunk and reset the counter, something like that?

Thank you

Carl

EDIT: Actually you would have 2 ints one for the x axis and one for the z axis otherwise it will only create "chunks" on the x or z axis?

avatar image DavidDebnar · Oct 19, 2011 at 05:08 PM 0
Share

Yes, you have to iterate trough your blocks and then add them to your chunks. One chunk is one gameobject so when you add a new block to it, just add the sides that are visible by code, do not instantiate if you want better (or even some) performance.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Sending Level Data over Network 1 Answer

cube based enging 1 Answer

I need to instantiate a bunch of objects without performance dips 1 Answer

Random generated debris in empty space 1 Answer

How Do I Fix My Grass? 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