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. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

[Released] DestroyIt - Cinematic Destruction System

Discussion in 'Assets and Asset Store' started by DeadlyAccurate, Jun 14, 2014.

  1. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Here is a step-by-step guide to using DestroyIt with MFPS 2.0 (ver 1.9) for multiplayer destruction.

    1) Create a new Unity 3D project.
    2) Import MFPS 2.0: Multiplayer FPS (version 1.9).
    3) An installer window should pop up after MFPS 2.0 is imported. Click Install. Follow the prompts, install the suggested dependencies, and enter your AppId to setup Photo PUN Multiplayer.
    4) Open the \MFPS\Scenes\ExampleLevel scene.
    5) When prompted, import TextMeshPro's TMP Essentials. You don't need to import the TMP Examples & Extras.
    6) Import DestroyIt.
    7) With the MFPS ExampleLevel scene open, choose Window => DestroyIt => Setup - Minimal from Unity's top menu.
    8) From the \DestroyIt\Demos (safe to delete)\Prefabs\Destructible Objects\Pristine folder, drag the Column prefab into the ExampleLevel scene. Place it on the ground somewhere where you can shoot it.
    9) Select the Column game object in the Hierarchy and choose Add Component => Photon View.
    10) Choose Manual on the Observable Search on the Photon View component. Then drag the Column game object to the Observed Components field, and check the Position and Rotation checkboxes under the Synchronize Options on the Photon Transform View component.

    11) Open the \DestroyIt\Scripts\Behaviors\Destructible.cs script and add the [Photon.Pun.PunRPC] attribute to the ApplyDamage method.
    Add the [Photon.Pun.PunRPC] attribute to the Destructible.cs script here:

    12) Open the \MFPS\Scripts\Weapon\Projectiles\bl_Bullet.cs script and add the section of code below to the OnHit method.
    Add this code...
    Code (CSharp):
    1. DestroyIt.Destructible destObj = hit.collider.gameObject.GetComponentInParent<DestroyIt.Destructible>();
    2. if (destObj != null)
    3. {
    4.     Photon.Pun.PhotonView pv = destObj.GetComponent<Photon.Pun.PhotonView>();
    5.     pv.RPC("ApplyDamage", Photon.Pun.RpcTarget.All, bulletData.Damage);
    6. }
    ...to the OnHit() method in bl_Bullet.cs here:

    13) Save all your changes to the scripts and the ExampleLevel scene.
    14) Run the scene. You should be able to shoot the column and destroy it. Also, you can try using it for cover, and you'll notice that the enemy's bullets are also able to damage and destroy the column. Not a safe place to hide anymore! :)


    Multiplayer

    The instructions provided below are if you want to test multiplayer destruction in your scene with another developer.

    1) Each developer on your team will need MFPS 2.0 and DestroyIt and have them imported into their project as outlined in steps 1-6 above.
    2) Next, we'll export the integration changes we did in steps 7-13 above into a unitypackage so they don't have to go through those steps. In the Project window, use CTRL-click to select the ExampleLevel scene and the two scripts you modified. Right-click and choose Export Package. Uncheck Include Dependencies so only the modified files are included.
    3) Have your developer friend delete his/her ExampleLevel scene and import your unitypackage, so you are both running the same code at this point.
    4) Now run the scene, and have your friend also run the scene on their computer. Note that they will also need to use the same Photon AppId as you.
    5) From the in-game menu, create a new server and Join. Your friend should join the other (enemy) side. Now when either of you damage or destroy the destructible column with a bullet, you will each see progressive damage and the destroyed particle effect.



    From here, you could expand the destructible integration to knives, grenades, molotov cocktails, etc. You could also try using a more advanced destructible object that has damage effects like smoke or sparks, or one that leaves persistent debris from a destroyed prefab.

    In the case of persistent debris, you might want to make the debris pieces observable to Photon by adding Photon View components to each of them and syncing the position/rotation. Or you might decide that you like persistent debris but don't want to worry about syncing each piece with all clients to save network traffic. It really depends on if the position of each piece of debris is important to track in you game. For example, if flying debris can damage players, block movement (ie, a cave collapse), or provide cover, then you probably want to track its position/rotation for all clients.
     
    Last edited: Mar 18, 2022
  2. glangor

    glangor

    Joined:
    Mar 24, 2013
    Posts:
    10
    Thanks so much for your detailed reply, I realised I hadn't responded. I did look into those areas, much appreciated!
     
    zangad likes this.
  3. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hi everyone,

    We have submitted a new version of DestroyIt (v1.15) to the Unity Asset Store. This new version works with Unity 2020 LTS and above, and is mainly focused around bug fixes and feature suggestions from customers. While we're waiting for the update to get approved, here are the patch notes and new feature highlights.

    New Features:
    * Feature: Added audio clip fields to the Destructible script, so it can play sounds when the object is damaged, repaired, or destroyed.
    * Feature: Added ability to scale Damage Effects prefabs on the Destructible script, much like how Fallback Particle Effect lets you override the scale on the Destructible script.
    * Feature: Added "Limit Damage" checkbox to Destructible script, so you can now specify Max and Min damage per hit, plus the minimum amount of time (in seconds) that must pass before the object can be damaged again. Really useful when you need rigidbody collisions to do a more predictable amount of damage.
    * Feature: Added a checkbox to DestructionManager that allows you to globally enable/disable damage to Destructible objects. This lets you turn on/off damage to destructible objects in one place.
    * Feature: Added Custom DestroyIt HDRP Lit shader and updated the DestroyIt User Guide on how to use it.
    * Feature: Fallback Particle Effects can now be set to Parent Under a transform. This is helpful for when you need the particle effect to follow along under a different game object.

    Minor Updates:
    * Updated: Code to work with Unity 2020.3.32f1 (LTS)
    * Re-centered the demo scenes so when they are opened for the first time (at world position 0,0,0) you see the scene correctly, instead of seeing a dark area with no terrain.
    * Removed the "DestroyIt-Ready" feature and removed the mentions of it in the User Guide PDF.
    * Added a ShockwaveSphere script, which is similar to the nuke's Shockwave Trigger Wall script, but this one moves out as a radius from the initial blast instead of as a wall.

    Bug Fixes:
    * Fixed: Damage Levels were not recalculating when totalHitPoints were modified at runtime through code. TotalHitPoints and CurrentHitPoints are now public properties with backing fields.
    * Fixed: DamageLevel hitpoint ranges are no longer cast to integers, which was causing an issue with destructible objects with very low hit points (ie, 5hp total with 5 damage levels) not progressing to the next damage level properly.
    * Fixed: Set ObjectPool container to inactive to prevent unwanted OnEnable events (such as destroyed sounds) when scene starts.
    * Fixed: ObjectPool no longer throws errors about "key already exists with that instance ID" when using nested prefab copies of Destructible objects.
    * Fixed: Moved the Particle Alpha (no fog) shader out of the "Demos (safe to delete)" folder, because the default particles use them and they are therefore required for the main DestroyIt asset. Now you can delete the Demos folder and not get pink textures on the default particle effects.
    * Fixed: Objects with DontDoDamage tag were doing damage to static destructible objects and destructible objects without rigidbodies.
    * Fixed: Issue with HitEffects where it was only playing the first effect found. Now plays all effects.
    * Fixed: Small issue with StructuralSupport script where it would only remove joints that had connected rigidbodies. Changed it so it removes all FixedJoints.

    New Feature Highlights:


    Audio Clips:
    You can now drag audio clips to the Destructible script and it will play the clip whenever the destructible object is destroyed, damaged, or repaired.

    (Check out Scenario #31 in the Main Scenarios Scene to try it out.)




    Damage Limits:
    You can now select Limit Damage on the Destructible script and specify the minimum and maximum damage done each time the object is damaged. This can be really useful for controlling how much damage rigidbody projectiles do to destructible objects, or for integrating DestroyIt with other assets that use a different health/hit point scale.

    You can also control how much time must pass before the object can be damaged again. This is useful when your destructible objects have complex colliders and might be hit multiple times by fast-moving rigidbodies (like a cannon ball). Normally, this would cause a lot of damage to the object, but now you can set it to only be damaged once per second for example, which would ignore the extra ricochet hits.

    (Check out Scenario #32 in the Main Scenarios Scene to try it out.)



    Enable/Disable Damage Globally:
    On the Destruction Manager, you can now turn on/off all damage to Destructible objects with one checkbox. This might be useful when you want to jump to a cut scene or important dialog in your game, and you don't want random damage and destruction to interfere. Or when you switch scenes, you may want to disable damage until the scene has fully loaded and open dialog windows have been resolved.



    Override Scale of Damage Effects:
    Much like how you can override the scale of the fallback particle effect, you can now override the scale of each Damage Effect on the Destructible script.



    Custom Shader Graph HDRP Lit Shader for Progressive Damage:
    As mentioned in this post, the custom HDRP shader we've been providing to customers on the forum is now included in the DestroyIt asset package.

    Enjoy! And if you run into any issues, please let us know.
     
    ledshok and EpicMcDude like this.
  4. EpicMcDude

    EpicMcDude

    Joined:
    Apr 15, 2013
    Posts:
    79
    Dude yessss, this is looking like a great update! I was very happy to see an update notification for Destroyit. Thank you for supporting it!
     
    zangad likes this.
  5. tj_hooka

    tj_hooka

    Joined:
    Jul 4, 2019
    Posts:
    4
    Been having issues with trees, made a prefab(Using the palm_PRISTINE included in demo, health changed to 1) that I can place on terrain and can run into with a car, but the terrain tree versions don't react. I have tree collisions disabled on terrain but it just smacks to a stop without destroying the tree.

    Otherwise it's been interesting so far!
     
  6. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hi @tj_hooka,

    Hopefully we can help you get the vehicle damaging terrain trees. First, a couple of questions:

    1) Are you using a vehicle controller system asset? If so, which one? Each vehicle controller system does things a little differently. Some don't have rigidbodies on their vehicles. Does your vehicle have a collider and rigidbody on it? What is the mass of the vehicle's rigidbody? If you let me know which vehicle controller system you're using, I can try to reproduce it on my end (if we also own that system) and let you know what you need to modify to get things working with that system.

    2) Are the trees taking damage, but just not enough to destroy them? Or are they not taking any damage at all? If they are taking some damage, you may just need to adjust the mass of the vehicle so the impact has more collision magnitude. Or maybe adjust the hit points of the trees down a bit. The way you can find out if the tree is taking damage is to switch to scene view while the game is running, find the destructible tree stand-in (there should be an invisible collider around the tree that intercepts collisions) and check the Destructible script on the tree stand-in.

    Edit: Oh, one other easy way to check if your tree is taking any damage at all, is to enable the Limit Damage checkbox on the Destructible script and set the Minimum damage to something high, like 1000 hit points. This way, even if the tree is bumped and takes a point of damage, it will instead take 1000 damage and destroy the tree. If you set the Min damage to 1000 and it still doesn't destroy when you hit it with the vehicle, then it's not taking any damage, and I suspect that would be because your vehicle doesn't have a rigidbody, or the collider/rigidbody setup is configured differently. Regardless, it's good info to know for troubleshooting.
     
    Last edited: Apr 22, 2022
  7. tj_hooka

    tj_hooka

    Joined:
    Jul 4, 2019
    Posts:
    4
    Hey Zangad, Did try the minimum damage trick and setting HP of the tree to 1 but no such luck.

    1. Yes, have tried Edy's Vehicle Physics and another vehicle physics engine included in another asset. Will be trying rcc and nwh soonish. The prefabs I place work, but terrain trees don't. Colliders and Rigidbodies on the car, mass typically around 1000.

    2. There is collision but no damage. (Car stops instantly).

    I'll keep trying and probably throw a car into the destroyit demo with a terrain tree and smash some stuff to see if it's something to do with how I did the terrain.

    Using Unity 2020.3.33f1 and Universal RP.
     
    zangad likes this.
  8. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hey @tj_hooka,

    Thanks for the info. Since I also have Edy's Vehicle Physics, I took a look at reproducing the issue in our demo scene and found a few things that need to be tweaked to get cars destroying trees.

    I made a video of the changes, but it turned into more of a tech-focused troubleshooting discussion rather than a step-by-step. But I'll post both here in case you're curious about the troubleshooting stuff.

    Destructible Terrain Trees + Edy's Vehicle Physics (Step-By-Step)

    1)
    Import Edy's Vehicle Physics into your DestroyIt project (or vice-versa)
    2) Drag one of Edy's vehicle prefabs into the scene
    3) Drag Edy's Camera Controller prefab into the scene and point it to follow your vehicle's transform
    4) Delete DestroyIt's First Person Controller from the scene
    5) Delete DestroyIt's HUD from the scene
    6) Make a code change to line 242 in the TreeManager.cs script in the UpdateTrees() function so it doesn't strip off Rigidbodies from trees. Add this: && comp.GetType() != typeof(Rigidbody)
    7) Click the "Update Trees" button on the TreeManager component in the scene to update the tree stand-ins to now have rigidbodies
    8) Comment out line 464 in the Destructible.cs script in the OnCollisionEnter function: "if (!isActiveAndEnabled) return;". This will prevent collisions from being ignored on disabled Destructible scripts.

    Destructible Terrain Trees + Edy's Vehicle Physics (Video)



    Hope that helps! Let me know if you still have issues.
     
    Last edited: May 5, 2022
  9. tj_hooka

    tj_hooka

    Joined:
    Jul 4, 2019
    Posts:
    4
    Thanks very much for your help and glad to see you did videos for a handful of the Vehicles Physics packs cause I've been using a variety in different engines and seeing how you were troubleshooting was cool.



    Got lots more stuff to integrate/fix up but I'm glad it's going!
     
    zangad likes this.
  10. ParadoxSolutions

    ParadoxSolutions

    Joined:
    Jul 27, 2015
    Posts:
    319
    If there is anyone who doesn't want to pay the big bucks for RayFire but doesn't like Blender's cell fracture I found this free fracture tool for Unity on GitHub: https://github.com/U3DC/unity-libre-fracture

    Works pretty well.
     
    EpicMcDude and zangad like this.
  11. Nachoman

    Nachoman

    Joined:
    Oct 25, 2013
    Posts:
    2
    Hi, i bought this asset with humble bundle, but i can't find it in the packagemanager. All other assets are available. This is the only one that doesn't work. Any Idea?
     
  12. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hi @Nachoman,

    That's odd, no I'm not sure what could be going on, there. We haven't had any other reports of this issue so far, but thanks for bringing it to our attention.

    Unfortunately, we don't have any control over the keys, but I would imagine that you can let Humble or Unity know and they should be able to get you setup.

    Here is the customer support for Humble. Just explain that you are missing your key for DestroyIt and give them your Transaction ID: https://support.humblebundle.com/hc/en-us/requests/new

    And here is the customer support for Unity. You should be able to just copy/paste what you filled out on the Humble form, and let them know you're not seeing DestroyIt in your package manager.
    https://support.unity.com/hc/en-us/requests/new?ticket_form_id=65905

    I've also had good results just directly messaging companies on Twitter. Both Unity and Humble are very active, there.
     
    Last edited: Sep 23, 2022
  13. Dyntragos

    Dyntragos

    Joined:
    Jul 24, 2018
    Posts:
    28
    Hello, I've purchased The DestroyIt asset, and I'm tying to use it in conjunction with the PolygonDungeon asset pack, but I'm having trouble getting the progressive damage to display on the prefab objects in the pack. I added the details mask and the secondary masks as instructed, but no progressive damage will show. I simply press 0 four times to make the objects explode, but the progressive damage aspect is important the project I'm working on. It looks as thought the detail maps do not display anything when used with the mesh objects for the PolygonDungeon prefabs, because when I switch the mesh on the object to a standard cube, the damage displays correctly.

    If there is anything I can do to fix this, it would be much appreciated!
     
  14. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hi @Dyntragos,

    I have that pack, too, so I took a look at it and I see the same issue. Looking at the textures, I see the problem. The Synty models have UVs that point to a single pixel of color on the texture images. This allows Synty to produce an entire model pack with only 4 textures/materials. The downside is that there's very little texture data to work with. This means you can't use a detail map with these models, as far as I can tell.

    To clarify, the secondary detail map/mask *is* being used, you can see that the damage texture is being overlayed on top of the image correctly (the cracks in the bottom right of the material ball). But you don't see it on the barrel because the barrel's UVs only point to a couple of pixels on the texture.



    If I keep adjusting the offset/tiling of the damage texture, I can get it to where the cracks cover one or more of the pixels that the UV of the model points to, but that just makes a large portion of the barrel black - not really what we're looking for.

    So unfortunately, I don't see a way to use DestroyIt's progressive damage system with Synty models, or any low-poly models that only use a few pixels of texture data. There just isn't enough texture data on the model to display complex cracks or damage.

    The only ways I can think of to get this to work would be to re-UV the models you want to use with progressive damage, and make those models use a regular-sized texture and a different material. That's pretty complicated, though, and very labor intensive if you wanted to do a lot of assets that way. Plus, it kind of defeats the reason to use a low-poly pack like Synty's that has such a high degree of texture optimization. But re-UVing them would make the models have progressive damage with DestroyIt.

    The other way would be to use projectors to project damage textures onto the model. But that would probably be pretty bad, performance-wise. You would need to project the damage textures from multiple angles around the model, which means each of your models would need 6-8 projectors that would have dynamically-progressive images switched out at runtime. Not a simple task. But that would make it so you don't have to modify the models and still get the higher-resolution complex damage projected onto them.
     
    Dyntragos likes this.
  15. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hey @Dyntragos,

    I thought of another way you can get some progressive damage textures working with Synty models: adding a new UV map to the model and assigning the Secondary Map images to that. That way, you don't have to re-UV and re-texture every model, and the steps are pretty simple.

    Here's the results (the barrel is from Synty's Dungeon Pack):
    https://www.modelshark.com/content/images/DestroyIt-Synty-Barrel.gif

    Here's the steps to add the second UV map and setup the material in DestroyIt:
     
    shyamarama and Dyntragos like this.
  16. Joymagine

    Joymagine

    Joined:
    Nov 13, 2022
    Posts:
    1
    Terrain Trees with multiple Terrains in the Tree Manager?
    i could probably write it myself but throwing the question to you for a moment.
    Thanks.

    ...

    I got my car working with the Terrain Trees with your video :D

    now I got like 25 terrains in one scene ( car game need decently big level )

    I suppose the idea is to only have 1 active terrain, but that kinda doesnt work especially at an intersection.

    also Iam kinda newbie to terrains, but i thought having multiple 1km x 1km terrains was the way to go, especially I got tools that can handle editing on them well.
     
  17. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hi @Joymagine,

    Yes, as it's written, DestroyIt expects to handle only one active terrain in the scene. But you can change this if you know some coding, which it sounds like you do.

    What I would do is change the terrain public member variable on the TreeManager to an array, and either drag and drop my terrains into the array at design time, or programmatically load them into the array at runtime. Then, change the code in the OnEnable() method in TreeManager to loop through all the terrains in the terrain array and store all their terrain data in a dictionary, with the dictionary key being the index of the array, so you can keep track of which terrain each tree came from.

    Pretty much every method in TreeManager would need to be touched, to change from a single terrain to an array (or dictionary with the terrain index as key). But the logic shouldn't need to change - it's still just destroying and replacing terrain tree data at a specific coordinate on the terrain with the prototypes you've previously defined.

    One thing to note is that performance may be an issue if you're trying to manage thousands of destructible terrain trees across 25 terrains in a single scene. It probably comes down to how many total trees you have, how complex your colliders for them are, and how many trees the player can see/destroy at once.
     
    Joymagine likes this.
  18. dfernand

    dfernand

    Joined:
    Jun 21, 2014
    Posts:
    7
    Will DestroyIt used with a URP Pipeline Unity project work on a gaming console target platform e.g. PS4, PS5, XBox One etc. ? I'm asking because Rayfire which is another 3D destructive package will NOT work for videogame consoles.
     
  19. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hi there,

    DestroyIt does work with the URP pipeline, but we haven’t tested it with a console target platform, so I can’t say for sure whether it would work with that or not.
     
    dfernand likes this.
  20. bbaugh007

    bbaugh007

    Joined:
    Jul 23, 2018
    Posts:
    38
    Hello, is there a tutorial for working with support points to make more realistic holes in walls when a cannonball goes through? I'm unsure of how support points work and how to prevent new destructible objects from exploding entirely when receiving damage.
     
  21. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Hi @bbaugh007,

    The support points are really designed to just add a little clinging debris to objects that are supported by other, larger structures - like a window in a building - the system is there to let some of the pieces continue clinging to the frame for a more realistic effect. I wouldn't try to use support points to make realistic cannonball holes through doors.

    For that, you would first need to break your object up a lot, into really small pieces. Probably 100-200 or more debris pieces for a single wall. Performance will become an issue quickly if you create an entire building made of walls with this many debris pieces, but it can be done.

    I'm not sure I understand what you mean by objects exploding entirely when they receive damage - that sounds like you are using a particle effect and maybe the cannonball is doing too much damage and you have Can Be Obliterated checked on your Destructible object. If that is checked, then when it receives 3x the amount of damage it has, then it just explodes into the particle effect. You can turn this off by un-checking Can Be Obliterated. Also, if you are only using a fallback particle effect (no destroyed prefab), you will get that same effect because there is nothing else for the object to destroy into.
     
    bbaugh007 likes this.
  22. bbaugh007

    bbaugh007

    Joined:
    Jul 23, 2018
    Posts:
    38
    The goal is to have an imported house object's walls behave like the walls of the example tower object in the attached images.
     

    Attached Files:

    Last edited: Dec 1, 2022
  23. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    332
    Oh ok, so you just need to know how to use the cling points to get the same effect as the tower in the demo scene?

    We don't have a video tutorial of that process specifically, but if you look in the DestroyIt User Guide on page 14 it illustrates how to position the Cling Points.

    From the user guide:

    "You add the Cling Point script to colliders on your destroyed prefab. When debris is spawned, the DestroyIt system looks for cling points and raycasts against adjacent colliders. If the raycast hits something, it rolls a percent chance based on Chance to Cling that you specify. If it passes that check, it strips the rigidbodies off the debris piece and parents it under the object it clings to. This provides better performance and a rock-solid joint over hinge joints.

    To the right is an illustration showing how cling points appear in the inspector. This is the destroyed prefab for the glass pane. On the edges, you can see the “pin” gizmos that indicate the direction the raycasts will be fired from the debris piece to check for adjacent colliders to cling to."


    So you just need to place the Cling Points so the pin gizmos point to the object you want the debris piece to cling to. I hope that helps. Please let me know if you have any specific issues getting it to work.