Search Unity

Destruction with DOTS

Discussion in 'Entity Component System' started by PranavSK, Oct 15, 2019.

  1. PranavSK

    PranavSK

    Joined:
    Jan 14, 2016
    Posts:
    2
    As an experiment I am trying to see if we can have a destruction system in DOTS. This is mostly inspired from the recent Chaos Framework in UE4. I am curious to see if anyone has tried this in the community and would like to get an idea on how to proceed.

    I have some fairly simple idea. Regardless of whether we do real-time or pre baked the approach for ECS is probably to destroy the existing full mesh entity and replace it with chunk mesh entities.

    Another idea when using baked destruction is to take advantage of the sub scene and apply the algorithm to the entire sub scene to prevent repetition in chunks.

    We could also use the blob assets to store info about the connections of chunk to provide more realistic physics (although I have no idea about blobs and dots physics)

    Curious to see what other people have done to implement destruction.
     
    bb8_1 and Opeth001 like this.
  2. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    So I tried my hand at converting ElasticSea's project (https://github.com/ElasticSea/Destructible-Walls) to dots with a somewhat limited degree of success. The code is messy and unoptimised and generally unfinished but it could give you a starting point. Or maybe give me feedback on how to improve it :)

    If you want to give it a try or fork or whatever, its available https://github.com/thelebaron/Destructibles on the "dots" branch
    Notes:
    - To make a new fractureable object, add a FractureAuthoring script to a new gameobject.
    -Select the mesh you want fractured, as well as the inside and outside materials. The other options have no effect for now.
    -Set the chunks number but anything in triple digits may take forever(probably a candidate for jobifying).
    -Click "Fracture Mesh".
    -Select one or more of the child Chunk objects and set isAnchor to true, click "Finalise" there or on the FractureAuthoring script "Find Anchors".
    -Press play and click a part of the mesh to "damage" it, or enable it as a physics object. If you click the anchor, the whole object should collapse.
    Also note the camera has some scripts for damaging the nodes.

    Now what I couldn't really figure out was how to make the "connection graph" part of it work properly, the connections don't go the most optimal route and with gizmos on you will see that it sometimes builds the most elaborate and windy path to the anchor. I don't have any experience with algorithms for this kind of thing(dijkstra's shortest path was something that I wanted to try to figure out but never got around to it), so it could kinda fake simpler stuff but with more fractures, the flaws are pretty noticeable.
    Other issues:
    - It is probably incompatible with subscenes, due to it creating more entities at conversion time that dont have a gameobject representation(not sure if this is a subscene but or expected behaviour but thats another story).
    - When there are a ton of chunks, the HybridRenderer appears to slow down, not sure if this is just me or not.
    - Theres no real strain system at all, its either connected or its not(no slowly breaking apart).
    - The biggest might be Im unsure how this affects unity's dots architecture as far as mesh per chunk usage. Would several really heavily fractured objects just use up all the cache with unique chunks per mesh? This has stuck to the back of my mind ever since I saw chaos and was thinking of it in terms of dots. Would really like to hear an official response for this question.

    Finally I never considered blobs but that might be a far better way to represent the graph part(compared to my solution of buffers upon buffers).

    gif -
     
    Last edited: Oct 15, 2019
    bb8_1, sateyr, YurySedyakin and 4 others like this.
  3. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    128
    Hey, awesome demo! Do you plan to further work on it ?
     
  4. Stepan_33

    Stepan_33

    Joined:
    Nov 21, 2022
    Posts:
    26
    Hello. Can I use this system for my commercial games?

    Is it possible to make your program use already prepared fragments and not create its own?

    https://forum.unity.com/threads/nvidia-blast.472623/
    This forum is about how to properly divide an object into pieces
     
    Last edited: May 28, 2023
  5. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    @Stepan_33 I think there's room for improvement, and its been so long I don't really recall how easy it is to slot in your own fragments, though I cant imagine its too much effort to do so(maybe just replacing some prefabs?), though when I worked on this the idea was to use the builtin fracturing tools to negate the need for it. License is MIT so go crazy.

    I would like to revisit this at some point in the future especially if Unity ever implements simpler rigidbodies(3/4dof) that they mentioned as possibilities, you could get some pretty crazy scaled destruction games going.
     
  6. Stepan_33

    Stepan_33

    Joined:
    Nov 21, 2022
    Posts:
    26
    I have studied this topic a lot, then as other people do, with other assets for unity, I came to the conclusion that the best way would be to make your own joint that will calculate the load on the object The most difficult thing here is to make the Rigidbody count several objects as one, because if you use a standard (joint) in unity, then it will all be very not optimized and it will behave like jelly, there is another rather spectacular way for this method, we need to divide our object into imaginary groups that we will make physical at the right time, let's say we have a wall that we divide into 2, 3 groups of debris, each of these groups can be destroyed even more by a couple more groups, the most difficult thing is to optimize This work, and do software in the unity editor that will help you do this,
    when we want to make a destruction for unity, we need to remember how it works in real life and simplify it, (joint) is one of the best ways (not counting optimization), for greater efficiency, we can make the strength of the johnette gap depend on the contact area of the fragment
     
  7. Stepan_33

    Stepan_33

    Joined:
    Nov 21, 2022
    Posts:
    26


    A really cool video on how to work with a huge number of physical objects, but the question is whether this will cause more problems when creating a game
     
  8. Stepan_33

    Stepan_33

    Joined:
    Nov 21, 2022
    Posts:
    26
    It remains a big question whether it is possible to use both the built-in Rigidbody and physics through DOTS in the game so that they interact correctly with each other
     
    Krnitheesh16 likes this.