Search Unity

[Released] Voxel Destruction

Discussion in 'Assets and Asset Store' started by Atangames, Apr 29, 2023.

  1. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,

    This is the forum for the package "Voxel Destruction".

    You can find it here: Asset Store

    The ultimate tool for creating immersive and realistic destruction effects in your Unity games! With voxel-based physics and a user-friendly interface, Voxel Destruction allows you to create detailed destruction effects that will leave players amazed. Whether you're creating a shooter, a survival game, or an action-adventure game, Voxel Destruction provides the features and tools you need to take your game to the next level. With support for large-scale destruction, destructible terrain, and dynamic objects, Voxel Destruction makes it easy to create immersive, interactive environments that players will love.



    → Directly load from MagicaVoxels .vox files:
    This Package allows you to model anything in the free Voxel Modeling Software "MagicaVoxel" and then save it in the StreamingAssets folder and directly load them in Unity.

    → Supported Platforms:
    Windows: ✔️
    Linux: ✔️ Tested on Ubuntu and Fedora, should work on most distros
    Android: ✔️ Note: Streaming Assets don't work as expected on aab files, but it works fine with apk
    WebGL: ✔️ Uses Webrequests to read Streaming Assets
    VR: ❔ Worked on a Oculus quest 1, but I can't guarantee that it works on all headsets.
    MacOS and IOS: ❓ Not tested, I can't guarantee that it works

    → Greedy Meshing:
    It is using a fast Greedy Meshing algorithm that combines neighbor faces together to save processing power.

    → Collapsing:
    The package automatically detects voxel groups that are no longer connected to the main voxel object and separates them into a fragment.

    → Performance:
    The Package is using the Unity Job system to make the Greedy Meshing calculations multithreaded, you can choose between a simple Job a ForJob and a ParallelForJob.
     
  2. StCost

    StCost

    Joined:
    Mar 1, 2017
    Posts:
    30
    Looks great

    Does it have some kind of LODs? Would be great to use it in procedural infinite world
    Also if there would be an option to smooth out the blocky voxels - I'd be glad to buy the asset
     
  3. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,

    No the package does not have any LOD system and does not support procedural world generation.
    However, it would be possible to use the package to build a world generation system, but it would require a lot of changes in the code.
     
  4. mugundan-animator

    mugundan-animator

    Joined:
    Nov 29, 2017
    Posts:
    1
    How this collapsing system works?
     
  5. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,
    the collapsing system is a job that runs in the background after a destruction occurred. It calculates all pieces that are not connected to each other and separates all except the largest piece.
     
    Stormer2020 likes this.
  6. unity_3755162BF7B60DBDA3C1

    unity_3755162BF7B60DBDA3C1

    Joined:
    Apr 18, 2022
    Posts:
    3
    I have a prefab containing about 100 voxel objects, when I press a button I will instantiate this prefab, the problem is it takes a lot of time to instantiate. About 1 minute.
    Can I speed it up faster?
     
  7. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    I think the best way would be to minimize the count of voxel objects, but it depends on what you are using it for. Try to merge some of these objects in magicavoxel, you can put them on another layer so they get drawn separately.

    "Precalculated fragments" is the fastest destruction type, but it also takes the longest to load, maybe consider using normal fragmentation on some smaller voxel objects. Finally for very small objects you could consider just using normal prefabs, instead of destruction.

    Hope that helps!
     
  8. unity_2E34E38A63FC37AD9428

    unity_2E34E38A63FC37AD9428

    Joined:
    Dec 23, 2021
    Posts:
    1
    Atangames Hello! I have a problem with destruction. When the object is on the stage, there are no problems with destruction. But when the object appears after the "Instantiate" method, the object is not destroyed, or is not destroyed correctly. The problem occurs more often on android devices. How to spawn correctly?
     
    Last edited: Jul 11, 2023
  9. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,
    Instantiating the object should not be a problem, maybe the problem is caused by the script that creates the destruction. Make sure to use GetComponentInParent and GetComponentInChildren when checking for voxel objects.

    If this does not solve your issue, please enable "debug" on your voxel object and send me some more info on what is happening.
     
  10. unity_3755162BF7B60DBDA3C1

    unity_3755162BF7B60DBDA3C1

    Joined:
    Apr 18, 2022
    Posts:
    3
    Somtime a got this errror and voxel object can't be destroy anymore :

    ObjectDisposedException: Cannot access a disposed object.
    Object name: 'The NativeArray is already disposed.'.
     
  11. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi, could you please send me the exact error with stacktrace and a screenshot of you voxel object settings. It would help me to understand what is causing the problem.
     
  12. unity_3755162BF7B60DBDA3C1

    unity_3755162BF7B60DBDA3C1

    Joined:
    Apr 18, 2022
    Posts:
    3
  13. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,

    I submitted an update that should fix the issue, it still needs to go through the unity verification process and should be life in a few days.
     
  14. andreymixler

    andreymixler

    Joined:
    Nov 25, 2022
    Posts:
    2
    Hello i have a problem.
    If I put "Build all childs", then all my objects appear in one chunk.
    Help me please ^^ upload_2023-7-27_14-14-48.png
     
  15. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi, the package is not able to get the global position you placed voxel objects on. You will need to disable build all childs and creating a voxel object for each object in your vox file.
     
  16. basil3

    basil3

    Joined:
    Dec 3, 2015
    Posts:
    29
    Hi,

    Just purchased the asset and I've been playing around in Magicavoxel and exporting some test objects to work out the best workflow for my use case and have had a bit of trouble with the asset being able to read the .vox files.

    Essentially, the 'export' function (selecting .vox) in Magicavoxel saves the file as a .vox file but this doesn't seem to be able to be read by the Voxel Object script when trying to build the mesh.

    If I use 'Save project as' in Magicavoxel this again creates a .vox file and this can be read by the Voxel Object script and the mesh builds fine.

    Perhaps I am missing something completely!!

    For context, I would like to create my entire model within Magicavoxel made up of separate objects and then bring that into Unity and apply destruction to just certain parts of the model.

    My idea is to have a root gameobject that is my 'model' in Unity and have children which make up each part of the model. Each child would be an individual gameobject with it's own Voxel Object script and referencing it's own separate .vox file for that part (that way I can control destruction on a per part basis).

    I thought I could easily achieve this by having one master project in Magicavoxel and then exporting each individual selection as a separate .vox file but that function produces a file that does not seem to be able to be read by the Voxel Object script. For now I have to do the above and then open the file and save as to overwrite it and then it works.

    If you need any further information let me know.

    B
     
  17. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,

    You should always use the direct ".vox" files and not export them as a seperate ".vox". This should make things easier for you since you can just import your vox files into unity and to make changes just open it using magicavoxel, edit them and safe the changes. No need for reimporting.

    The workflow you are talking about should be easily achievable using the package. You can use the main vox file you have, assign it to a voxelobject, disable "build all childs" and select the index of the layer. You can then do this and create voxel objects for every layer in the vox file you desire.

    I hope that I was able to help you, there also is a setup video on the assetstore page that should help with problems like this.
     
    basil3 likes this.
  18. Amitos

    Amitos

    Joined:
    Feb 13, 2021
    Posts:
    4
    Hello, I'm wondering if it's possible to recreate the voxel slicing feature from the game "Clone Drone In The Danger Zone" using this asset. If so, could you explain how to do it?

    In that game the player is able to slice off voxels from models using a sword as seen in the picture image.png
     
  19. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,
    The package does not really have a slicing feature, but it would be possible to develope one yourself. The package would only help you building a mesh out of VoxelData, so you will have to write all the slicing logic yourself. Keep in mind that the package is not designed for usecases like this and you will need to rewrite a lot of code.
     
  20. ILYICHZC

    ILYICHZC

    Joined:
    Apr 28, 2017
    Posts:
    1
    Hi. In your demo game it's possible to get into buildings using wholes of destruction. Also it's possible to throw weapons inside. But in your demo scene in Unity editor, buildings have mesh colliders which prevents to go or throw something inside. What do I need to set up in the scene to have same ability?
     
  21. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi, as long as the buildings do not have a convex mesh collider it should still be possible to enter them. Make sure that "start with physics" and "use convex collider" are disabled. You can also turn of collapsing since that can also trigger activation of physics.
     
  22. zeliailun

    zeliailun

    Joined:
    May 22, 2017
    Posts:
    3
    2023.2 unable to use
     
  23. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,
    Could you please include more details?

    There is a compatibility issue with newer versions of the Collections package, for anyone encountering that here is a simple fix:

    To fix this issue, you can:
    - Either you downgrade to an older collections package that is still using the old syntax (1.2.4 for example)
    - Or you can fix the code, which only requires you to change 4 lines of code (lines 69-72 in MeshBuilderSafe.cs) to this:
    unnamed (1).png
     
  24. zeliailun

    zeliailun

    Joined:
    May 22, 2017
    Posts:
    3
    Okay, it can run now.
     
  25. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    236
    Hi, I'm looking for a voxel system for a Doom style game, but with destructible terrain and monsters.

    There are some things I want to ask.

    I want to build the levels and all objects from voxels, preferable with a voxel density similar to to the res of Doom textures/sprites. Is that possible?

    Is it possible to make the detached voxels, from destroyed walls and killed monsters, to attach to the ground and be persistent?

    Can you set damage thresholds and damage types on the voxels? I don't want any weapon to be able to break everything.

    What kind of shaders can I use? Can I recolour individual voxels in an object?

    I guess saving/loading changes to the levels from destruction is no issue?

    Thanks.
     
  26. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,

    Using this assets to destroy maps with the resolution of the original Doom textures, will not work with decent performance. There would already be large lag when creating the mesh and destruction would just make it worse. If you really want to have such a small voxel size you will probably need to look into voxel raytracing.
    However, you could build the levels using voxels and place it as normal model into the scene and then add small destructible parts like walls and other objects.

    Attaching destroyed voxels to the ground is not possible, but you could add it yourself.

    There are options to modify the strength of destruction, but you can't change the behavior of different type voxels in the same object.

    The asset uses a vertex color shader, because the colors of the voxels get assigned as vertex colors. You can recolour individual voxels, but you will need to add some code for that.

    Loading/Saving changes to the level is also something you would need to build on your own, the asset only allows you to reset a voxel object but there is no functionality to save the destruction state and information about all fragments.

    I would recommend you to build you own solution, because of your unique use case. You could still try the asset and just refund it if it does not work for your project.
     
  27. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    236
    That's sad to hear. Didn't know this was so unusual since I've seen tech demos and voxel mods for Doom for 20 years or so. The thing is I can't program so I was looking for something I could play around with while also make use of Unitys features. But yea, it's really hard to find anything out there.
     
  28. bozydar104

    bozydar104

    Joined:
    Jan 2, 2024
    Posts:
    1
    Hi

    I made map using a lot of objects using this asset, when i hit play button game infinitely tries to get to play mode, but after that i thought, maybe i will try to build and run game then, but when i turn on app its shows unity logo and then freezes, do you how to help me?

    Thanks
     
  29. andreycom13

    andreycom13

    Joined:
    Jan 20, 2017
    Posts:
    2
    Hello! I am getting sliced objects from your code, but there is a problem. Everything works fine except for assembly on Android and specifically when spawning from a prefab. At this point in the code the coordinates are not correct. The line number is slightly different from the original, since I added several of my events to your code. Help me please! upload_2024-1-19_1-50-36.png
     
  30. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,

    If you are using Precalculated Fragments make sure that you hit Build Voxel Object before running the game. It could also be that you just have such a large amount of voxel objects that it is unable to load the game.
     
  31. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,

    Changing the code should not break the calculated coordinates. Make sure the fragment array contains the right data, maybe try to debug log some more information or try if it works without your changes.
     
  32. VolvoMan

    VolvoMan

    Joined:
    Dec 17, 2022
    Posts:
    9
    Hello

    Is it fine to use this asset even if I don't want destructible objects? In other words, I would use this asset for optimizing MagicaVoxel models. I might want destruction to work on some models, but not all.

    Otherwise, an option is to use both your asset and the "Voxel toolkit" asset. I would use your asset for destructible objects and the Voxel toolkit for models that don't need to be destructible, but need to be optimized.
     
  33. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,

    yes this asset can be used for non destructible voxel objects, but the mesh will be less optimized. The asset also can't handle meta information like the material of a voxel, so it is up to you to decide what better fits your porpuse.
     
  34. TreborJones

    TreborJones

    Joined:
    Feb 5, 2015
    Posts:
    18
    Hi, I'm attempting to 'cut' an object in two, is this possible or will it always create one side of the object and the rest will fall away/dissapear? The effect I'm aiming for is similar to cutting through a plank of wood and retaining both sides of the cut plank. Thanks for any direction or advice.
     
  35. Atangames

    Atangames

    Joined:
    Sep 16, 2020
    Posts:
    22
    Hi,
    I think this effect should be possible to achieve using precalculated fragments. If you enable physics for the voxelobject, the 2 parts should behave in the same way.
     
    TreborJones likes this.