Search Unity

Uniblocks: cube-based infinite voxel terrain engine

Discussion in 'Assets and Asset Store' started by RawLionWorkshop, Feb 2, 2014.

  1. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello,

    I am having a Problem with my lights. First I just added them to the Scene and that was okay.
    But if a chunk is removed, I want the light to be removed, too. So I now want to set the chunk as the light's parent.

    But it does not work. The light seems to have the wrong Position? I am a bit confused with world Position, chunk index (multiplied with sidelength == Position?) and father - Position.

    So I start the function with world Position of the desired light position:

    Code (CSharp):
    1.  
    2. public static void AddLight (int x, int y, int z, ushort voxel, Chunk chunk = null)
    3.     {
    4.         try {
    5.                 Vector3 startVec = new Vector3 (x, y, z);
    6.                 if (chunk == null) {
    7.                     Index index = Engine.PositionToChunkIndex (startVec);
    8.                     if (index == null)
    9.                         Debug.LogError ("AddLight Error index null");
    10.                     chunk = ChunkManager.GetChunkComponent (index);
    11.                     if (chunk == null) {
    12.                         index = Engine.PositionToChunkIndex (startVec - Vector3.up);
    13.                         if (index == null)
    14.                             Debug.LogError ("AddLight Error index null");
    15.                         chunk = ChunkManager.GetChunkComponent (index);
    16.                         if (chunk == null) {
    17.                             Debug.LogWarning ("AddLight Error chunk null for position: " + startVec);                    
    18.                     }
    19.                 }
    20.              
    21.                 GameObject lightGameObject = new GameObject ("ChunkLight" + voxel);
    22.                 if (chunk != null)
    23.                     lightGameObject.transform.parent = chunk.transform;
    24.                 Light lightComp = lightGameObject.AddComponent<Light> ();
    25.                 lightComp.range = 8;
    26.                 float up = 0.2f;
    27.                 lightComp.intensity = 2;
    28.                 lightComp.color = Color.yellow;
    29.                 lightComp.shadows = LightShadows.Soft;
    30.                 lightComp.enabled = true;
    31.                 lightComp.type = LightType.Point;
    32.                 // Before setting the parent, this worked!!
    33. //                if (voxel == 202)
    34. //                    lightGameObject.transform.position = new Vector3 (x + 1, y + up, z + 1);
    35. //                else
    36. //                    lightGameObject.transform.position = new Vector3 (x, y + up, z);
    37.                 // LocalPosition relative to parent position, which is chunk?
    38.                 if (voxel == 202)
    39.                     lightGameObject.transform.localPosition = new Vector3 (x + 1-chunk.ChunkIndex.x * chunk.SideLength, y + up-chunk.ChunkIndex.y * chunk.SideLength, z + 1-chunk.ChunkIndex.z * chunk.SideLength);
    40.                 else
    41.                     lightGameObject.transform.localPosition = new Vector3 (x - chunk.ChunkIndex.x * chunk.SideLength, y + up-chunk.ChunkIndex.y * chunk.SideLength, z - chunk.ChunkIndex.z * chunk.SideLength);
    42.             }
    43.         }
    44.         catch (System.Exception ex) {
    45.             Debug.LogError ("AddLight Error: " + ex.ToString ());
    46.         }

    This does also not work. Any idea please?
    Code (CSharp):
    1.  
    2.                 if (voxel == 202)
    3.                     lightGameObject.transform.localPosition = new Vector3 (x + 1-chunk.transform.position.x, y + up-chunk.transform.position.y, z + 1-chunk.transform.position.z);
    4.                 else
    5.                     lightGameObject.transform.localPosition = new Vector3 (x - chunk.transform.position.x, y + up-chunk.transform.position.y, z - chunk.transform.position.z);
    6.  
     
    Last edited: May 20, 2017
  2. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello,

    I have one other huge problem remaining in uniblocks.
    I am not sure if it is a bug or something I do wrong:

    I have not only one but many voxels like this with a ”real” mesh.

    Collider is set to “Mesh” and “Custom mesh” is on.

    I have a very simple OnLook routine in it, which sets my cursor:
    Code (CSharp):
    1.     public override void OnLook (VoxelInfo voxelInfo)
    2.     {
    3.         try
    4.         {      
    5.             {
    6.                 Globals.InfoClick = "Click to travel to a known portal";
    7.                 Globals.MousePanelBehaviour.SetCursor(MousePanelBehavior.CursorPart.Left, Globals.MousePanelBehaviour.CursorPortal, 0,1,true);
    8.                 Globals.IsCursorSet = true;
    9.                 if (Globals.SelectedBlockGraphics != null && Globals.BolEditor) {
    10.                     Globals.SelectedBlockGraphics.transform.position = voxelInfo.chunk.VoxelIndexToPosition (voxelInfo.index);
    11.                     Globals.SetSelectedBlockFromVoxel(voxelInfo);
    12.                 }
    13.             }
    14.         } catch
    15.         {
    16.             Debug.LogWarning ("VoxelPortal OnLook Error");
    17.         }
    18.     }
    This works on my shrine in the lower half of the mesh, in my portal it works only one the left front ground.
    Both are larger than one basic voxel.

    Is it a bug? The collider itself seems to work, I can stand on the mesh, but for larger mesh there only seems to be a small area where I get the mouse cursor in OnLook...

    A solution would be great! Thanks a lot!
     
  3. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello together,

    I found the OnLook and also OnMouseDown Problem, the source is here:

    In the Engine.cs:

    Code (CSharp):
    1.         public static VoxelInfo VoxelRaycast (Vector3 origin, Vector3 direction, float range, bool ignoreTransparent)
    2.         {
    3.             try {      
    4.                 RaycastHit hit = new RaycastHit ();
    5.      
    6.                 if (Physics.Raycast (origin, direction, out hit, range)) {
    7.          
    8.                     if (hit.collider.GetComponent<Chunk> () != null
    9.                         || hit.collider.GetComponent<ChunkExtension> () != null) { // check if we're actually hitting a chunk
    10.              
    11.                         GameObject hitObject = hit.collider.gameObject;
    12.              
    13.                         if (hitObject.GetComponent<ChunkExtension> () != null) { // if we hit a mesh container instead of a chunk
    14.                             hitObject = hitObject.transform.parent.gameObject; // swap the mesh container for the actual chunk object
    15.                         }
    16.  
    17.                         int offSet = 0;
    18.                         Index hitIndex = hitObject.GetComponent<Chunk> ().PositionToVoxelIndex (hit.point, hit.normal, false);
    It only works if you raycast in on it's exact Position, right?

    Has anybody found a solution for all voxels which are bigger then one block only?

    Thanks a lot!
     
  4. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    OnLook will only return the correct block if you're looking directly at the 1x1x1 block, so for example for opening/closing the default door, it will only work when looking at the bottom. This is just the way Uniblocks is designed - every custom mesh has a cube-shaped collider for raycasts at the origin position of the voxel.
    That's because the raycast returns voxels based on the location of the raycast hit, and if the custom mesh goes outside of its 1x1x1 block and the raycast hits it there, then the position returned would be for a different voxel, because the position would be outside of the original voxel.
    There is no other way to check which block the mesh belongs to, because the entire chunk is one big combined mesh.

    I don't know of any good way to solve this at the level of the engine itself, but you could use a workaround. For example, for custom meshes that are two blocks tall, you could set the block above each custom block to a different voxel that has the same OnLook effect as your original block.


    So the x,y,z and startVec are an absolute world position? If so, you can just use that to position the light, i don't see why it wouldn't work. It shouldn't matter if the light is parented to the chunk or not, just use lightGameObject.transform.position = startVec to set the absolute position of the light.

    Otherwise you can get the correct world position from a specific voxel in a chunk using Chunk.VoxelIndexToPosition, and use that to set the light's absolute position. There should be no need to calculate the position manually by multiplying the xyz by chunk length, etc.
     
    Firlefanz73 likes this.
  5. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Thanks a lot for the info maap!
     
  6. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello,

    there is a Unity 2017 Release Candidate out now, which has multithreading Support.

    Anybody tried that for Uniblocks? Especially for Uniblocks this would be the best improvement ever :)
    I still love Uniblocks but the spawn Performance is the biggest Problem...

    Or will there be an update of Uniblocks? That would be great!
     
  7. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    For your Information:

    Now Unity 2017 is released. I have experienced no Problems with updating my game, and spawning landscape really got much faster/performant! Spawning is pretty good now.

    Still Rendering could be a bit faster, if anybody knows good hints besides of using as few chunk materials as possible, please share them :)
     
  8. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    259
    I have bought UniBlocks recently I was very happy with the results but one question...is there's a way I can assign a health variable to each voxel and decrease/increase it t runtime? and can you please give me a code snippet if this's possible in UniBlocks?
     
  9. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    You should know in memory, you will have hundreds of chunks, each one has hundreds of voxels.

    Have a look in the Voxel.cs, which stands for one voxel,or in the Chunk.cs, which is a chunk that contains it's voxels. You could add that in the voxel.cs, but I would not recommend it.

    It gets too large in memory and when your landscape changes are written to disk. It gets way too slow when updating each voxel.

    I did growth and stuff like that like this:

    Have for example x Kinds of your plant from seed to small to big each in it's own voxel.

    Have a ChunkUpdate Method, which is updated randomly. There cycle your voxels in that chunk and have a random to Switch to the next planth growth Level...

    Just my thoughts :)
     
    WinterboltGames likes this.
  10. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    259
    I totally forget about that (silly me), what I was thinking of was check for the chunk that the player is in (I know how to do that easily) and update the blocks that are in that chunk (that what I don't know how to do) do you have any idea about an override-able VoxelUpdate method? I tried doing on but end up lagging to -1 fps (just kidding I wanted to give you an idea about how much lag do I get)
    I have a computer the following specs:
    128 GB ram
    Nvidia GTX 1080
    16 TB of hard drive
    Intel i7 4.2 GHz
     
  11. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    259
    Firlefanz73 about multithreading...I have started looking into how to implement it in UniBlocks for my smooth voxel survival game (kinda like 7 Days To Die game)

    I have been doing multithreading on multiple projects and I think I'm a near expert in doing so (over 31 projects with multithreading)

    so, if you are interested I could send you some of the files to test them for me
     
  12. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I am interested. I am doing most Thing with StartCoroutines (Unity 2017) now, and it works pretty well. I guess my bottleneck for Performance are gfx now, but I am interested if it gets better with your classes.

    In my Playercontroller.cs LateUpdate method I do it like this:

    Code (CSharp):
    1.                 if (currentChunkUpdateTime > 0.4f) {
    2.                     Index index = Engine.PositionToChunkIndex (transform.position);
    3.                     if (index != null) {
    4.                         Chunk chunk = ChunkManager.GetChunkComponent (index);
    5.                         if (chunk != null) {
    6.                             currentChunkUpdateTime = 0;
    7.                             chunk.UpdateChunk ();
    Then in Chunk.cs:

    Code (CSharp):
    1.         public void UpdateChunk ()
    2.         {
    3.             try {
    4.                 if (!isChunkUpdating) {
    5.                     isChunkUpdating = true;
    6.                     StartCoroutine (ChunkUpdate ());
    7.                }
    8.             }
    9.             catch {
    10.                 Debug.LogWarning ("Chunk Updater Error");
    11.             }
    12.         }
    Also in the Chunk.cs:

    Code (CSharp):
    1.         private IEnumerator ChunkUpdate ()
    2.         {
    3.             try {
    4.                 bool hasChanged = false;
    5.                 // for each voxel in Voxels, check
    6.                 //if (chunk != null)
    7.                 //{
    8.                 for (int x = 0; x < SideLength; x++) {
    9.                     for (int y = 0; y < SideLength; y++) {
    10.                        for (int z = 0; z < SideLength; z++) {
    11.                             ushort voxel = GetVoxelSimple (x, y, z); // the current voxel data
    ....do voxel stuff here!

    I do it like that.

    And one Thing I can reccomend: Use a texture Atlas. I am using 8 materials in my chunk prefab. I cannot use less than that. This should be the absolute maximum...

    PS: I am still trying to find a water shader, that can work with a texture Atlas. I want to use one material for blue water, poison water and Lava. If you find something please let me know :)
     
    Last edited: Aug 4, 2017
  13. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I would also be interested you can you can view and how much fps you get when you run my game.
    If you want to test it, I could sent you a build. I also have an I7 with 16 GB but only a GTX 1060.
    Would be interesting to see what far distance and fps that would be on your System.
    I increase far distance when having many Frames and decrease it when few Frames...
     
  14. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    259
    that would be cool send me a demo of your project and let me test it for with you with my custom multi threading also water...I thought I do an adjacent block check to see if it's empty or not if yes the block mesh changes to the next stage size (i am not perfect at speaking English so sorry for any understandable words) like this 1st stage (full water block) ||||| ---> 2nd stage |||| ---> 3rd stage ||| ---> 4rth stage || ---> then 5th stage | ---> then empty no water is this an efficient way of doing Minecraft-ish water? and I am working on a water shader when done I would happily send it to you.
     
  15. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    If you want to Exchange some Knowledge and Code, I could sent you my Routine for water and growth (I would open a private thread here). It may not be perfect, but it works pretty well. If you enhance it, let me know.

    I am also interested in multithreading! I already do, but I do not know if it is good, I do not have much Knowledge there.
    If you do shaders, I would suggest alway Support Texture Atlas / Texture Coordinates. So you can do water (maybe even different Kinds of water) and Lava with one material and shader!

    I asked a shader developer to do this for me. I didn't get something to test yet. Right now I am using a Standard water shader.
     
  16. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    259

    Go Ahead...
     
  17. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    No, everything is fine. If you have a question, or want or need something, let me know...
    If you find something to improve, that would be great, please let me know :)

    My build game is 2,3 GB and zipped 1 GB, I can try to upload it this night if you want to Play around...

    PS: the zip had the HudFPS included. This is very interesting: I set the camera far distance by the fps I receive. And the chunk creation depth, too. You can try for yourself, if you want to. Makes the game smooth in my opinion.
     
  18. italicranger

    italicranger

    Joined:
    Jul 7, 2017
    Posts:
    1
    hey everyone, I started using uniblocks a couple weeks ago i have made a minecraft like water and inventory, (((but i cant figure out how to do a health system for the blocks, i would be willing to pay someone for help writing one if they have time.)))

    i think i figured this out finally sorry for the trouble, anyways hi everyone !!!!!
     
    Last edited: Aug 9, 2017
  19. Grinchi

    Grinchi

    Joined:
    Apr 19, 2014
    Posts:
    130
    got the problem with unity 2017 getting error all the time.

    ArgumentException: An element with the same key already exists in the dictionary.
    System.Collections.Generic.Dictionary`2[System.String,Uniblocks.Chunk].Add (System.String key, Uniblocks.Chunk value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
    Uniblocks.ChunkManager.RegisterChunk (Uniblocks.Chunk chunk) (at Assets/Uniblocks/UniblocksScripts/Core/ChunkManager.cs:91)
    Uniblocks.Chunk.Awake () (at Assets/Uniblocks/UniblocksScripts/Core/Chunk.cs:52)
    UnityEngine.Object:Instantiate(GameObject, Vector3, Quaternion)
    Uniblocks.<SpawnMissingChunks>c__Iterator1:MoveNext() (at Assets/Uniblocks/UniblocksScripts/Core/ChunkManager.cs:324)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    Uniblocks.ChunkManager:StartSpawnChunks(Int32, Int32, Int32) (at Assets/Uniblocks/UniblocksScripts/Core/ChunkManager.cs:231)
    Uniblocks.ChunkManager:TrySpawnChunks(Int32, Int32, Int32) (at Assets/Uniblocks/UniblocksScripts/Core/ChunkManager.cs:197)
    Uniblocks.ChunkManager:SpawnChunks(Int32, Int32, Int32) (at Assets/Uniblocks/UniblocksScripts/Core/ChunkManager.cs:185)
    Uniblocks.ChunkLoader:Update() (at Assets/Uniblocks/UniblocksScripts/PlayerInteraction/ChunkLoader.cs:39)
     
  20. Grinchi

    Grinchi

    Joined:
    Apr 19, 2014
    Posts:
    130
    Anyone ? ? ? ? is this thread dead ? :(
     
  21. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I am afraid yes. Has been only a dialogue between two users last months.
    I am using Unity 2017, too. It works fine for me (not using Network stuff).

    I believe it is something you changed in your own project?
    Maybe with the engine or the chunkmanager or something...
    Seems to try to add a chunk which has already been added.
    Did you try to add multithreading and now the same chunk can be added multiple times?
    Just guessing.
     
  22. Grinchi

    Grinchi

    Joined:
    Apr 19, 2014
    Posts:
    130
    i just imported package default from store nothing else and it games that error
     
  23. Grinchi

    Grinchi

    Joined:
    Apr 19, 2014
    Posts:
    130
    i do not need network. the problem is that the index of the chunk is same when calling
    // Set variables
    ChunkIndex = new Index (transform.position);

    was thinking that the problem was in my project but same for store version
     
  24. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Now I can reproduce it. I installed update to 2017.1.1p2, and now I got the same Problem and see no chunk anymore.
    Before I had 2017.1.f1 and was okay...

    Did you find a solution for this?
     
  25. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    In Chunk.cs

    ChunkManager.RegisterChunk (this);

    works only one time for the very first chunk, then never again with the duplicate key error from above....
    Maybe the Chunks Dictionary in the Chunkmanager works not like before in latest Unity.
     
    Last edited: Sep 18, 2017
  26. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    It helps if you install the latest release (2017.1.1f1), not the latest patch Version from unity.
    After I installed the latest patch Version, I had the same Problem.
    Since I found no Workaround, I reinstalled the latest release and everything was fine again.
     
  27. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello maap,

    I hope you read this. Uniblocks is not working anymore with the latest patch release from unity. I do not know if it is a bug in unity that will be solved in future, or if they changed something on the dictionary Features which Needs to be changed in Uniblocks, please have a look. :)
     
  28. Grinchi

    Grinchi

    Joined:
    Apr 19, 2014
    Posts:
    130
    Same on f1 its working but not on patch :( what about multi threading ?
     
  29. nuonical

    nuonical

    Joined:
    Feb 28, 2015
    Posts:
    46
    There is no multithreading included. I coded my own for the level generation and mesh generation, but it was a pain in the butt.

    As for the "ChunkManager.RegisterChunk (this);" error, has anyone tried simply adding a "if(!ChunkList.Contains(whatever))" ? I don't have this error, so I'm not sure where the issue is exactly, but happy to help if you can narrow it down.
     
    marlonial likes this.
  30. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello,

    Before I added all particle Systems and lights directly into the Scene. This is bad, you Need to destroy them yourself then etc.

    I now added them as a chunk child. Works so far, but when I get Close watching them, the particlesystem turn off somehow. In the inspector they still look okay, but I cannot see them anymore, or they do not spawn anymore...

    Any idea why?
     
  31. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I think I will add them to a gameobject pool as child, and in late update enable/disable them to Player distance.
    Or is there a better way? I thought chunk childs are a good idea...
     
  32. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Asset deprecated any info ?
     
  33. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Yes, it seems so. Too bad.
    I am still using it. Some working multi-threading for unity 2018 would have been great!
    It still is a good asset in my opinion.
     
  34. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Hey! have you managed to add multi-threading to the engine?
    with the current setup, using coroutines I get lag spikes whenever chunks are being generated.
    trying to change it to support multi-threading but with no luck so far.
     
  35. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I did not get it working, or at least not so good I would use it.

    I want to upgrade soon to Unity 2018, then gibe it a new try.
     
  36. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    I am yet to read Unity's 2018 log, anything interesting in there worth updating for? better support for multi-threading or something?
     
  37. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I think multithreading was improved and new Job functions for multithreading are available with it.
     
  38. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Upgraded to Unity 2018, I think it's best to wait a bit before upgrading.
    Anyways, I'm implementing the multi-threading to Uniblocks, I hope to get an optimized version up and running at the end of the weekend.
     
  39. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I you get it working, I would be very interested in it. Maybe we could Exchange Knowledge, I habe my game playable in early Access now, maybe I can help you with some other Knowledge / script in Exchange.
     
  40. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I found this here:

    https://github.com/Unity-Technologies/AutoLOD

    I did not get it Working, but sounds interesting. and for your multi-threading:
    This includes a thread-safe mesh class! See "WorkingMesh"
    I guess this could be helpful...
     
  41. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Thanks! might save some time!
    I am currently planning the steps on paper but I would like your advice.
    For starters, at the 'ChunkManager' script one of the main functions is 'SpawnMissingChunks ()' which runs on a coroutine and constantly updates the main loop as long as the chunkQueue is empty.

    I thought about setting it up this way:
    At main thread's update() always check if action delegate list in empty, if not run it's action. (as unity doesn't allow for child threads to create new instances or modify existing ones.)
    Other than that, create child thread to work with meshes (as much as possible without sending back to main thread.) and spawning in general.

    The main thing is to figure out what is the best way of handling distance changes and deciding what chunks should be destroyed/created (see in 'ChunkManager', SpawnMissingChunks () main loop.)
    We can use a coroutine to keep on looping through it or use an infinite child thread to do it (I am not even sure if it is worth it because of unity's child threading).

    I am probably missing a lot of stuff here but I would love to hear your advice.
     
  42. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I added in Chunk.cs LateUpdate

    float distance = Vector3.Distance (Globals.PlayerGameObject.transform.position, transform.position);

    the distance to my player. And deactivated my own "Growing stuff" method if it is far away, and deactivated the chunk itself it is more far away than Camera FarClipPlane.

    You could try a Pool of Chunks that is linked to the ChunkManager or own thread in there that does Nothing but Spawn missing chunks if Closer than FarClipPlane?

    I never did get this working myself in a way it way faster with multi-threading...
     
  43. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Maybe with the threadsafe Mesh it could also be possible to just multi-thread the single chunk building or updating?

    I guess that would be a lot easier and would be a great Advantage already.
     
  44. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Check this out, found an asset that allows you to switch between threads in coroutines, should solve your problem.
    https://forum.unity.com/threads/rel...-run-co-routines-on-background-thread.232755/
     
  45. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Thanks for the info,
    but it is from 2014 and I think I tried exactly this one 2 years ago when I started my game but I am not sure.
     
  46. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    To be fair, it works fairly well, the only downside is that it's only available with coroutines.
    According to Unity's profiler all we need to multi-thread is the terrain generation and as you said the meshes, mainly the RebuildMesh() in Chunk's script, I will let you know if I get it to work.
     
  47. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    By the way, did you publish your game?
     
  48. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
  49. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
  50. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Sorry was away for a while! I will definitely check it out today or tomorrow and message you my opinion.


    I've decided to put it aside for now but once I get to the optimization part of my project I will let you know if I succeed.


    I have a question regarding this subject, I have a chest in game which is 2 vertical blocks long but only one block is clickable with voxelevents and etc... I know it's possible to use onLook to solve a part of it will leave you still able to place blocks in that area. Just wanted to see how did you deal with it.