Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Minecraft like game - slow chunk loading

Discussion in 'Scripting' started by Wolv15, Dec 9, 2015.

  1. Wolv15

    Wolv15

    Joined:
    Nov 21, 2015
    Posts:
    5
    Hello. I'm working on Minecraft-like game but I want it to run on mobile devices. I have one problem. I'm instantiating chunks from prefab. Chunk is one object build with vertex data of his blocks. No physic yet, simple mobile shader. Game run with 60 fps on Xperia E(42fps with physic)(1 core - 800mhz, 512mb ram) but when i walk and game must load chunks, fps drops on something like 10 and after loading goes back to 60. I'm loading only chunks in front of player, and deleting chunks that are too far away but still I'm getting poor performance on loading. To generate mesh I'm using threading, for perlin noise I'm using threading but It's impossible to use threads for Unity3D operations and I'm kinda stuck. This drop happends on every device(mobile/pc). After a lot of optymalization with variables int->byte, I manage to load chunks in real time 8 chunks per frame with 60 fps on PC but on mobile I still get like 16fps. I found one way. Loading one chunk and pass the frame but it also cutting the performance and chunk loading is really slow. Any ideas? I can think of one. Drop Unity3d and write this from the bottom in opengl using threading everywhere but I really want to avoid this. I try to use simplex noise instead of perlin but it gives maybe 6 fps?

    P.S My chunks are 16x16.
    P.S.S I'm disabling blocks faces that are not visible. On my 8 core(1.7Ghz) smartphone fps drops to 30 fps too. It's not only about cpu if old 1 core 800Mhz cpu have 10-15 fps on chunk loading and 8 core 1.7Ghz cpu has 25-30 fps on chunk loading.
     
    Last edited: Dec 9, 2015
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    What goes into your loading of chunks?

    Is there disk reading?

    How much of it doesn't depend on the unity api?

    Could your thread out everything except for the 'Instantiate' calls?
     
  3. Wolv15

    Wolv15

    Joined:
    Nov 21, 2015
    Posts:
    5
    If chunk was generated before(save on the disk) then it is loaded from disk.

    Yes

    Only Instantiate use UnityAPI, saving and loading data is done by .NET API for now, later I will use [Application] from Unity.Api to locate folder where game is installed on Android/IOS.

    Yep. I could throw some for loops from ChunkLoading.cs into threads but this loops just run function CreateChunk(x,y,z) and this function has Instantiate in it. From this point everything is threaded - perlin noise, serialization, mesh data.

    To be sure I disabled save/load chunks and let them all be generated. This does nothing at all, maybe 2/3 fps boost on loading. I delete functions like Awake, Start, or even constructor from Chunk script but this is still not good ;/

    On start i wrote my ChunkLoad function but it was not well optymalized, then i found this site and use ChunkLoad script from there: http://alexstv.com/index.php/posts/unity-voxel-block-tutorial-pt-7
    I edited it to load less chunks, and stop delete function to avoid Destroy(). I know this increase drawcall and memory useage but for now it is not my problem ;p.

    For example on android we have app called Exploration Lite and when this app is loading chunks we can't feel any fps drop not even a little chop. :|
     
  4. Wolv15

    Wolv15

    Joined:
    Nov 21, 2015
    Posts:
    5
    Ok I have an idea. I will start generating chunk from the top to the bottom. Then i switch to load only one chunk per 2 frames or even less. When player will be waking there by small fps drop and for him chunk will load in no time. Any other ideas?
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    I honestly have no idea how you go about loading these chunks, so... no.

    I have ideas how I'd go about accomplishing the task, but that's based completely on a foundational structure that I would have in mind. Not yours.
     
  6. Wolv15

    Wolv15

    Joined:
    Nov 21, 2015
    Posts:
    5
    Can you share some? This project is a basic code i could redesign it milion times until it will not be good enought. I wonder about perlin on gpu, load not loaded chunks data into ram(only changes are saved on disk), storing few more chunk data on game start and then when player moves use this data. When he stops and cpu is not used load more chunk data and when he moves use it. For example rendered chunk raius will be 5 chunk in each way, but data from disk will be 10 chunks each way. This will smooth game a little when player is not running fast and on far distance.