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 /
avatar image
1
Question by boop5 · Aug 02, 2014 at 03:41 PM · terrainvoxelminecraftchunks

How to load stacking chunks on the fly?

I'm currently working on an infinite world, mostly inspired by minecraft.
A Chunk consists of 16x16x16 blocks. A block(cube) is 1x1x1.

This runs very smoothly with a ViewRange of 12 Chunks (12x16) on my computer. Fine.
When I change the Chunk height to 256 this becomes - obviously - incredible laggy.

So what I basically want to do is stacking chunks. That means my world could be [∞,16,∞] Chunks large.

The question is now how to generate chunks on the fly?
At the moment I generate not existing chunks circular around my position (near to far). Since I don't stack chunks yet, this is not very complex.

As important side note here: I also want to have biomes, with different min/max height. So in Biome Flatlands the highest layer with blocks would be 8 (8x16) - in Biome Mountains the highest layer with blocks would be 14 (14x16). Just as example.

What I could do would be loading 1 Chunk above and below me for example.
But here the problem would be, that transitions between different bioms could be larger than one chunk on y.

Transitions between Biomes

My current chunk loading in action

Chunk Loading Example

For the completeness here my current chunk loading "algorithm"

 private IEnumerator UpdateChunks(){
     for (int i = 1; i < VIEW_RANGE; i += ChunkWidth) {
         float vr = i;
         for (float x = transform.position.x - vr; x < transform.position.x + vr; x += ChunkWidth) {
             for (float z = transform.position.z - vr; z < transform.position.z + vr; z += ChunkWidth) {

                 _pos.Set(x, 0, z); // no y, yet
                 _pos.x = Mathf.Floor(_pos.x/ChunkWidth)*ChunkWidth;
                 _pos.z = Mathf.Floor(_pos.z/ChunkWidth)*ChunkWidth;

                 Chunk chunk = Chunk.FindChunk(_pos);
                 
                 // If Chunk is already created, continue
                 if (chunk != null)
                     continue;

                 // Create a new Chunk..
                 chunk = (Chunk) Instantiate(ChunkFab, _pos, Quaternion.identity);
             }
         }
         // Skip to next frame
         yield return 0;
     }
 }


Update

kay here is a picture of a - what I call it - 'layered chunk'. Taken from Minecraft.

What you see here is actually one chunk - in sense of game mechanics. But in sense of logic / programming these are 16 chunks. 1x16x1 chunks.
So the uppermost layer is a noise-generated field (or whatever, a surface - to keep it simple) All underlying layers are 'filled' (every block is a material, not air).

Since the image is very large, I've decided to just link to the image. IMAGE

Update2:

Well while still thinking about this I came to the following idea, I'll try now:

Load every chunk on x/z viewrange. When the chunk is empty / transpernt (full of air) then I'll go as long as the chunk is empty go one layer down.

I think this should be a way to go. Maybe I'll always load the chunk below the loaded chunk, to avoid falling into a void.

Comment
Add comment · Show 3
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 robertbu · Aug 02, 2014 at 03:41 PM 0
Share

As a design problem, you may want to ask this on Unity Forums ins$$anonymous$$d of here.

avatar image boop5 · Aug 02, 2014 at 03:46 PM 0
Share

@robertbu Thanks for your answer - as always ;)
You already mentioned this at my last question - but I'm not sure in which sub-forum to post this question. Scripting ?

avatar image z3nth10n · Aug 02, 2014 at 03:50 PM 0
Share

Sorry for the off-topic, but your script looks cool! Could I see it, maybe I could help you, if you could use Skype it would be great! $$anonymous$$ine is: ikillnukes Bye! ^^

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Aug 02, 2014 at 04:14 PM

You don't need any fancy logic how to decide which chunk you should load next, Just create a "sorted job queue". So all you do is adding just the position (of logical representation of your chunks) that are within the current view range into a list. You then sort the list by the distance of the chunk from the player. The nearest ones are generated first.

When moving around you would check in intervals if all chunks in the view range of the player are already loaded. if not, add them to the loading list.

Your loading coroutine just picks a chunk from the list (if there is any), removes that chunk from the loading list and loads the chunk.

You need of course another list to hold the currently loaded chunks. This is also important when you want to remove chunks too far away. Keep in mind to use a larger unloading radius and a smaller loading radius to prevent unnecessary loading / unloading when the player moves in a small area.

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 boop5 · Aug 02, 2014 at 04:26 PM 0
Share

Thanks for your answer, I really appreciate that. When you want to discuss, you can even join my Forum post here (as suggested by @robertbu)

Okay even when that makes sense but let me answer with an question:

$$anonymous$$y world is 256 Blocks high. When I'm at y 200. The lowest seen block is at y 150. Why shall I load chunks below this?

I don't have any chunk (un)loading yet - but it is obviously that if the count of loaded chunks rise, the performance sinks. So - why shall I load the 'useless' chunks?

$$anonymous$$aybe I get you wrong!

avatar image Bunny83 · Aug 03, 2014 at 09:35 PM 0
Share

Well, i'm not sure if i understand your question. Do you want to say that you have a max-view-distance of 50 blocks? That sounds a bit strange to me, however i don't know your world scale, i just compare with $$anonymous$$ecraft which has the exact same world layout (however in mc a chunk actually is from 0 to 255 which isn't possible in Unity since Unity only provides 16bit index buffers).

If your max-view-distance is greater than 50, how do you know that you can stop at 150? It depends on the content of each chunk if the chunk below is visible or not. Since it would be a mess to figure out if the chunk below is visible or completely covered you usually just load them all. At least all within your max-view-dist range.

$$anonymous$$eep in $$anonymous$$d that you only have to create surfaces which are adjacent to air / transparent blocks. If a surface of one voxel / block is covered by a solid block, it doesn't need to be drawn. That's what mc does. So a solid 100x100x100 block of stone (which consists of 1 million cubes and 6 million surfaces) would only need 60000 quads. This optimisation can be done perfectly in a thread as it is based solely on your voxel data.

I said that already a couple of times: A lot people look down at mc and think "such a primitive game" but it's actually one of the most advanced games when it comes to technology. $$anonymous$$c has come a long way and if you want comparable results it won't be much easier for you ;)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Tiled Terrain 0 Answers

Smooth Voxel terrain. How is it done? 2 Answers

Voxel based Terrain generation. Pointers please. 2 Answers

how to create chunks in voxel terrain generation 1 Answer

Anyone got a Voxel generator I can use? 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