volume.UpdateChunks(true) not working

0
Raja_Nukala posted this 03 July 2019

I used pica voxel terrain generation script for terrain generation. I want to add/delete cubes a'la Minecraft with tap to add and double tap to delete onto the terrain.

I'm using volume.UpdateAllChunksNextFrame(); its working fine but taking time...a lot of time ,whereas I need realtime update. I want to use volume.UpdateChuncks(true) but it's not updating, I tried using true/false as a parameter but it's not working.

Enclosed below is the code, can you suggest a solution?

https://pastebin.com/rdKtMXBK

Last edited 03 July 2019

4 Comments
Order By: Standard | Newest | Votes
0
GarethIW posted this 03 July 2019

I'd probably need to see some code or an example of what you're trying to do. Are you updating during generation, or is this for adding/removing single voxels after generation?

UpdateAllChunks() and UpdateAllChunksNextFrame() do what they say on the tin and update all chunks in the volume (either threaded or immediately). If you're setting a single voxel, you don't want to use these. If you're generating a volume, you would use this after you've set array data. But it's going to take more time the larger the volume, and there's no way around this. If you're generating a volume while the game is running, you should use UpdateAllChunks(), as it's threaded.

UpdateChunks() only updates chunks that have been changed via SetVoxel calls. You don't need to call this manually at runtime, as volumes will automatically call this each frame if needed.

0
GarethIW posted this 03 July 2019

Just saw your update. The script you're using is more geared toward box editing. Can I suggest that you look at this script:

https://gist.github.com/GarethIW/bb8634cef9e061d17049cdbc43213e1f

Which is a variation of the IslandsClickBoom.cs script in the PicaIslands demo. The above script is a hybrid unity physics/per-voxel collision test which supports building on top of existing voxels and also in chunks that have no voxels present. For a minecraft-style game, you probably don't need the second check in the script (the else block). You will need to have colliders enabled for the above script.

Last edited 03 July 2019

0
Raja_Nukala posted this 04 July 2019

Adding voxels it's working very quickly and now I want to know how to delete voxel in a quick way. Thanks for the quick reply.

Last edited 04 July 2019

0
Raja_Nukala posted this 04 July 2019

I tried the following code it's working as excepcted speed but not working all the time.

pvo = hit.collider.GetComponentInParent();

Vector3 checkPoint = hit.point + (ray.direction);

pvo.SetVoxelAtWorldPosition(checkPoint, new Voxel { State = VoxelState.Inactive });

Last edited 04 July 2019


Our 137 members have posted 528 times in 128 discussions