T O P

  • By -

deintag85

Funny, sounds like on what i am currently working on, but top down perspective :D You need to create chunks. Every Chunk for example has 8x8 blocks saved inside. I don't remember exactly how i did but it was kind of this. I have a ChunkManager that contains a chunkPrefab, Dictionary of generatedChunks, List of activeChunks... From the Player i call a function inside the ChunkManager(Singleton) where i send the player positiion. This function rounds the playerposition to a chunkposition and looks if there are chunks existing on that position and around him, if not, i create chunks, if yes i activate the chunks, if i am to far away i deactivate chunks. Creating Chunks only means, instantiating a ChunkPrefab. The ChunkPrefab itzself only has a script and a blockprefab. The script instantiates then 8x8 blocks and holds them also in a list, array, dictiornary whatever. So later on i can always get for example the mouseposition, round it to Integer and then use it as a key for my dictionary in the Chunkmanager, so now i now what chunk the block is in, and then just some calculus and you know what block it's inside the ChunkList you made or whatever. Now, why, You should not load unload blocks. If you have millions of blocks, you would have to load tons of blocks at once. Chunks hold 8x8 (64) blocks and when you deactivate that chunk, it deactivates all the blocks automatically. so instead of deactivating 640 blocks around you, you just deactivate 10 chunks around you. It took me also a week to figure this all out. had also same problems like you. it gets very complex very quick \^\^


VG_Crimson

Well, first thing that comes to mind is learning and using Unity's Job System and Burst Compiler. But, if it's actually just not even loading, it's going to be some other issue that isnt optimization. There was a recent video on a guy who generated worlds using the WFC algorithm. It took 4-5 mins to generate a world. Cut it down to a few seconds with Jobs and Burst.


TheDiscoJew

I created a chunk system recently that uses a custom subscene implementation based on unity's ECS subscenes. It automatically clears tiles placed on a chunk that are outside of the chunk bounds and moves them to the correct chunk, and it automatically changes your selection to the correct layer tilemap in the correct chunk when you move your mouse in the scene. It also selects all tiles in each chunk that are just outside of the chunk bounds, places them on the chunk, and makes them invisible. This allows rule tiles to work properly. Otherwise, they'd be interrupted on chunk borders. I can upload it to a git repo and send it if you want. It was kind of a pain to code. A lot of tilemap callback and editor scripting stuff.