Search Unity

Exploder [RELEASED]

Discussion in 'Assets and Asset Store' started by reindeer-games, Jul 12, 2013.

  1. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Newbie here.. hhmm .. it just ain't working

    been through the simple instructions and nothing is happening.

    tried an "Exploder" tag on the object I wish to blow up... & added the Exploder Object script to my character... collided him into the object.. nothing happens :(
    My game is a 3rdPerson game so the character has to make contact with the object to blow it up.

    I even tried a sphere landing on top of another sphere... one tagged "Exploder" & the other has Exploder Object script... Nothing

    This script should do it .. right ??

    void OnTriggerEnter (Collider other){
    if (other.tag == "Exploder") {
    ExploderSingleton.ExploderInstance.ExplodeObject(gameObject);

    ////////////////

    note: the demo scenes do work.

    Any reply would be greatly appreciated.
     
    Last edited: Oct 29, 2016
  2. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    hhmm.. no reply...

    was hoping at least some form of support would be in place moving into day 2.... & it's looking pretty grim... review time coming up...
     
  3. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi there,

    you can ignore the tag for now, calling ExplodeObject(gameObject) should be enough, but try do it like this:

    1) add ExploderPrefab to the scene
    2) create a script on your object you want to explode and your OnTriggerEnter...

    void OnTriggerEnter (Collider other){
    ExploderSingleton.ExploderInstance.ExplodeObject(gameObject);
    }

    3) also make sure there is some kind of collider on your object, otherwise OnTriggerEnter won't work
    4) if it's still not working please look at the examples script DemoClickExplode.cs included in the package, to make sure you are calling it correctly.

    5) if it's still does not work, you can send me your script and I can find the bug for you
     
  4. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Really appreciate the reply .. I'll give it crack

    here's the result

    Error:
    NullReferenceException: Object reference not set to an instance of an object
    ExplosionTest.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Exploder/ExplosionTest.cs:14)
     
    Last edited: Oct 30, 2016
  5. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Can
    It looks like there is some error in script "ExplosionTest.cs" on the line 14, could you copy/paste the whole script here?
     
  6. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547

    I noticed you are using OnTriggerEnter, just make sure you tick "IsTrigger" in your collider settings.
     
  7. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    yup the collider has i sTrigger ticked & still the same

    code reads :

    using UnityEngine;
    using System.Collections;
    using Exploder.Utils;

    public class ExplosionTest : MonoBehaviour {

    // Update is called once per frame
    void Update () {

    }

    void OnTriggerEnter (Collider other){

    ExploderSingleton.ExploderInstance.ExplodeObject(gameObject);
    }
    }
     
  8. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547

    It looks like you did not add Exploder prefab to the scene, I have tested your script and sample scene and got similar error if I remove the Exploder prefab from the scene. The prefab is located in Assets/Exploder/Prefabs/. Can you double check?
     
  9. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Great.. it works :) I had an Exploder game object.. but no Exploder Object script attached to it.


    Thanks so much for your help.

    hhmm... now with Exploder tag ?
     
    Last edited: Oct 30, 2016
  10. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    The tag is necessary only if you use radius explosion, so instead of calling ExplodeObject, you will call ExplodeRadius.

    Radius explosion means that Exploder will explode all objects in the radius tagged with "Exploder". But if you want to explode only one object, you can stick with "ExplodeObject" method, which is perfect for single object.
     
  11. summerian

    summerian

    Joined:
    Jul 6, 2014
    Posts:
    140
    Hey!

    How do I get the fragment list from a recently cracked object?
    Basically I want to enable and move the fragments myself like this

    Exploder.CrackObject(obj, OnCracked);

    private void OnCracked(float time, ExploderObject.ExplosionState state)
    {
    foreach (Fragment fragment in fragments)
    {
    // Remove rigibody and other components
    // Tween position of fragment
    }
    }


    I can't use
    var list = FragmentPool.Instance.GetActiveFragments();
    because they are not active.

    Thanks!
     
    Last edited: Nov 2, 2016
  12. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    that is not possible with current API, let me add it to the next release. Thanks for the feedback!
     
  13. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    actually it is already possible with FragmentPrefab and it will work with both Explode/Crack.

    Example:

    1) Create empty game object and assign this sample script:


    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class TweenFragment : MonoBehaviour
    5. {
    6.     public Transform TargetPos;
    7.     public float LerpTime;
    8.  
    9.     private Vector3 initPos;
    10.     private float time;
    11.  
    12.     void Start()
    13.     {
    14.        initPos = transform.position;
    15.        time = 0.0f;
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         time += Time.deltaTime * Random.value * 2;
    21.  
    22.         transform.position = Vector3.Lerp(initPos, TargetPos.position, time / LerpTime);
    23.     }
    24. }
    25.  
    26.  
    2) Set input to the sample script: target position and interpolation time.

    3) Drag & drop it to "Exploder prefab" in the Exploder inspector

    4) Disable colliders & Angular velocity & set Force to 0
     
  14. summerian

    summerian

    Joined:
    Jul 6, 2014
    Posts:
    140
    Excellent! This was exactly what i was looking for.

    Thanks a bunch for a great plugin.
     
    reindeer-games likes this.
  15. darkcser

    darkcser

    Joined:
    Oct 3, 2016
    Posts:
    10
    Does the Exploder work with 3D Text (i.e. 3D Object->3D Text)? I see that it works with planes but when I tried it with 3D Text nothing seems to happen. I was hoping to shatter 3D Text much like shattering a plane.
     
  16. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hello!
    Bugs, that i found
    1)After ExplodeCracked (and regular expose too) not every mesh has useGravity checked.

    2)Also ExploderObject.ExplosionState.ExplosionStarted not invoking.
    Test code
    Code (csharp):
    1.  
    2. exploder.ExplodeCracked(OnExplosion);
    3. ....
    4. private void OnExplosion(float time, ExploderObject.ExplosionState state)
    5.     {
    6.         switch (state)
    7.         {
    8.             case ExploderObject.ExplosionState.ExplosionStarted:    
    9.                 if (Debug.isDebugBuild)
    10.                     Debug.Log("ExplosionStarted");
    11.                 break;
    12.             case ExploderObject.ExplosionState.ExplosionFinished:
    13.                 if (Debug.isDebugBuild)
    14.                     Debug.Log("ExplosionFinished");    
    15.                 break;
    16.             default:
    17.                 break;
    18.         }
    19.     }
    20.  
    3)If i am using Singltone and regular explode, then mesh exploding ok, but in case of Explode self enabled (exploder script for each player's parent GO) exploder making some part duplicates


    And another one moment. Can i use cracked for multiplayer game, so can scene contains more then one cracked object(each for player)?
     
    Last edited: Nov 5, 2016
  17. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    unfortunately TextMesh does not work with Exploder, because there is no way to access the Mesh object (vertices/triangles/etc). Basically Exploder works only with Unity Mesh (MeshFilter component). But you might find some assets in the store that generate 3D text as a "real" mesh.
     
  18. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Thanks for the feedback, I am going to fix it.

    About the crack, this is not currently supported, but I want to put this feature to the next update because more people wish to use multiple cracks.

    Best,
    RG
     
  19. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    About 1) and 3) can you send me screenshot of you Exploder inspector? I can't reproduce it for some reason, maybe it's related to some specific settings.
     
  20. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424

    For both issues

    May be it has dublicates because GO has a lot of similar mesh...but active for ech state(legs, torso etc) always only one. So my suggestions: explode only active meshs, or only with by Scriptable
     
    Last edited: Nov 7, 2016
  21. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,486
    Hi, I see in the latest update "Exploder queue for sequential explosion", could I ask for some advice, how does that work? Is there any documentation on this?
     
  22. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, is is possible you can share your model with me? (Dropbox/google drive or email). I still can't reproduce it reliably.
     
  23. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    actually the queue was there quite a while already. It's an internal queue, not exposed to public API. The purpose of it is to allow Exploding multiple object in a row without waiting, for example you can call something like this:

    Code (CSharp):
    1. ExplodeObject(obj1);
    2. ExplodeObjec(obj2);
    3. ExplodeObject(obj3);
    Internally it will queue the explosions and process it one by one.
     
  24. Rainking

    Rainking

    Joined:
    Jun 10, 2013
    Posts:
    41
    Hi,

    After updating Exploder to the current version, I see a problem with my resulting fragments. Before the update, the inner side of my fragments had a texture. Now it has not. So I reviewed the Exploder sample and saw the Exploder Option Script and the Documentation about it, unfortunately, it is not working, and I don't know why. I guess it may have something to do with my LOD Meshes?!? Anyway, the inner side of my fragments is still empty even with the Option Script attached. Since there was no hint in the documentation where to attached the options script I found it in the samples (some hints how to apply it with LOD meshes would be cool).

    kind regards, Tino
     
  25. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    thanks a lot for feedback, it's probably related to your LOD, I can see the inner texture in my testing demos. Can you give me more details on how you use LOD meshes?
     
  26. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    a new version 1.6 was just released on the store.

    Changes:

    1) Improved performance, especially noticeably on mobile platforms. The cutting algorithm is equally distributed into background threads and doesn't choke the main Unity thread anymore. No more "Frame budget" option unless you disable multi-threading.

    2) Support for multiple cracks, example:

    Code (CSharp):
    1. void Awake()
    2. {
    3.     exploder.CrackObject(obj1);
    4.     exploder.CrackObject(obj2);
    5.     exploder.CrackObject(obj3);
    6. }
    7.  
    8. // later in the game
    9. exploder.ExplodeCracked(obj1);
    10. exploder.ExplodeCracked(obj2);
    11. exploder.ExplodeCracked(obj3);
    You can crack as many objects as your fragment pool can take. So for example if you have Fragment Pool Size set to 500, you can crack 5 objects with 100 fragments each, or 10 objects with 50 fragments, or 100 objects with 5 fragments each, etc.

    3) Bug fixes
     
  27. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    I'm very excited to check out the mobile performance. Is there a way to check the pool for number of available fragments before attempting a crack? Or possibly increase the number of fragments in the pool if insufficient? Thx
     
  28. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Ah, you got me, some API like this:

    bool CanCrack()
    int GetAvailableFragmentsCount()
    void ResizePool()

    Let me think about it and I will add make a quick fix later today.
     
  29. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    quick question... Will this still work in version pre 5.4.2? I'm in 5.3.6 and have several aging assets in dll form that I'm VERY leery about trying to update.
     
  30. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    yes, it will work, there are no API changes in Exploder regarding Unity 5.4.
     
  31. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,486
    Hi, I updated to version 1.6 and now see some errors:
    Assets/explodetest.js(20,16): BCE0019: 'Explode' is not a member of 'Exploder.ExploderObject'. Did you mean 'ExplodeRadius'?


    Script looks like:
    var myExploder : Exploder.ExploderObject;

    function Start () {
    myExploder = Exploder.Utils.ExploderSingleton.ExploderInstance;

    myExploder.Explode();
    }

    This worked before.
    What , if anything would I need to do to avoid this error?
     
  32. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi,

    I see you upgraded from a very old version, the API already changed a bit, the fix is easy:

    You just have to replace myExploder.Explode() into:

    1) myExploder.ExplodeRadius() - this will work same as Explode(), it will explode all objects in the radius
    2) myExploder.ExplodeObject(gameObject) - this will explode a single object you pass a parameter

    Le me know if you have more problems.
     
  33. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,486
    Hi, yep myExploder.ExplodeRadius() seems to help but the explode effect is much larger than before and effects performance, not sure why there is a such big performance drop, maybe the fragment pool size was reset to 500 again.
    Thanks for your help.
     
  34. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Did you get it work? It is possible that after update some of your old parameters were reset to "new" default. If the effect is larger it means "Target Fragments" is probably higher than before.
     
  35. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    I can confirm this asset totally rocks on mobile now! Tested on my LG G4 was very promising. Tests with a Samsung Galaxy s3 fared not so well but that phone can barely handle my game anyways... aaaand I do still have several non-mobile friendly options checked such as having the fragments use physics and gravity and such.

    Initially when I updated I didn't notice too great of a performance increase on mobile based on multithreading alone. The real gains came with cracking an object upon spawning (I'm using pooling) and calling ExplodeCracked(Gameobject) when they are set to be destroyed. The benefit of the ability to crack multiple objects now is HUGE regarding performance. Explosions happen (near?) instantly now instead of delaying multiple frames and I sometimes even notice a jump in frame rates as they explode (that NEVER happened before).

    But I noticed several issues of mine that I may not have noticed otherwise. Usually the first time my enemies exploded there was a huge frame rate drop then would usually improve thereafter although would sometimes still have a horrible lag, not always explained by garbage collection. Part of my problem was having individual exploder objects on each mesh, with varying amounts of pool fragments. So my initial fragment pool size was actually only 8 and would increase as enemies with larger pool amounts were spawned. As objects exploded and there were not enough fragments more were instantiated causing major slow downs that I incorrectly attributed as simply the cost of using Exploder. I solved this by having a "dummyExploder" object in the scene which has a fragment pool size of 500. This number should be more then enough for when I have the maximum enemies out and cracked. This would not normally be a problem for people using one exploder object.

    So from what I see now the last major hurdle with Exploder is garbage collection. I still get some explosions that cause a glaring pause as the GC is triggered. Any tips/thoughts on how to decrease garbage generation?
     
  36. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, your comment made my day! :) I am really happy to hear that.

    Now about the issues:
    1. I always recommend people to use single Exploder object (prefab) for the whole game with high fragment pool. If you have multiple Exploder configurations with different pool sizes, the cost of pool "resize" will affect your framerate a lot.
    2. First time explosion lags more than the others. I am aware of that, it's the first time "allocation" that can slow down the process. There is already a "dry run" explosion on Start() that kicks the memory allocator but I see it's not enough, I will look into that and increase the buffers.
    3. The GC. There are places I believe I can decrease allocations by using static buffers same as I already do in the mesh cutter but I think the biggest source of allocations and garbage collections comes from copying and releasing mesh data into fragment game objects. I don't have any tips for you now but it's definitely something I will focus on in the next release.
     
    christougher likes this.
  37. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Updated review on asset store... still 5 stars. :D

    Also, I have multiple reasons for each mesh having it's own exploder object. I don't want to accidentally explode the mesh of a nearby healthy enemy. I also have somewhat optimized the settings for each type with smaller enemies having much fewer fragments and such. I'm thinking as long as I have my dummy exploder object start out the scene with a high enough fragment count I shouldn't encounter any other performance hits related to the pooling or ever needing to resize the pool again. If I'm missing something glaring let me know.
     
  38. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Awesome thanks!

    You can consider using ExploderObject(<gameObject>) instead of ExplodeRadius(...). ExplodeObject destroys only the object you specify as a parameter and nothing else.
     
  39. randomtiger

    randomtiger

    Joined:
    May 23, 2013
    Posts:
    4
    Hi there, great plugin, I have a question:

    When I explode an object sometimes it breaks in fragments containing dups of some of the mesh, how do I prevent/minimise this?

    For example a teacup will explode and the results will contain more mesh that the original thing, its very obvious that the damage now contains two handles rather than one from the original model.

    Thanks.
     
  40. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Same here, I had just noticed this as well and hadn't had a chance to investigate...
     
  41. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi, sounds like a bug. I thought it was happening only with skinned meshes, which was fixed in latest update. But if it's still there I will investigate it.

    Thanks for the feedback.
     
  42. randomtiger

    randomtiger

    Joined:
    May 23, 2013
    Posts:
    4
    Thanks for your quick reply, the bug fix will improve the product I am working on

    I've been looking into your new feature of precracking since I am targeting mobile. The docs state "The disadvantage of using crack is that you cannot use more than one cracked object at the same time. You can crack only one object at the time, explode it and then crack a new one."

    Im taking this to mean I can only have have one object cracked at a time. Do you plan to remove this limitation at some point? Currently I have an exploder object per game object and so can precrack everything though I'm running into issues with the object that sets the core pool size being arbitrary. I was looking to moving to your standard solution of having one exploder object and moving it around (and changing its params depending on the target) but would like to be able to precrack everything in advance. I have plenty of memory to throw at this but need to try and maintain a high frame rate at all times.

    Thanks for your time
     
  43. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    That limitation is already removed now. Docs just don't reflect it. See the release notes :)
     
  44. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Yes, it's exactly as christougher said. The limitation is gone, I just need to update the docs.
     
  45. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    I have updated the docs.
     
  46. randomtiger

    randomtiger

    Joined:
    May 23, 2013
    Posts:
    4
    Thanks guys, I've refactored my system to use one exploder and it all seems to work well, including on mobile device. I've had to increase your default code pool limit though, I need more explosions :)
     
  47. azinicus

    azinicus

    Joined:
    Mar 20, 2016
    Posts:
    4
    Hi @reindeer-games we have been excited to use your asset since we saw it for our VR shooter game, so we implemented it this week, but have been having some trouble with the physics of our moving helicopters basically pausing for a few frames and then shooting the fragments out.

    So we have helicopters that are pooled/recycled after death (we don't instantiate them to save CPU cycles), so what we have to do is instantiate a destructible prefab when the helicopter is going through it's death function, assign the pre-existing physics attributes to that prefab, then explode it + add our particle effects... which are pretty cool, except that dang pause that happens right before fragmentation.

    Here's a video of this "pause" in action: https://dl.dropboxusercontent.com/u/7673/RLTYCHK/Fragment helicopter pause.mp4

    Screenshot of our exploder prefab settings: http://take.ms/dwcTL

    This is how we're instantiating the fragmentable prefab from our original helicopter object:

    GameObject dp = (GameObject) Instantiate (defragmentPrefab,transform.position,transform.rotation);
    dp.GetComponent<Rigidbody> ().velocity = GetComponent<Rigidbody> ().velocity;

    Finally, our destructable script that's on the prefab that actually fragments:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Exploder.Utils;
    using Exploder;

    public class DestructableObject : MonoBehaviour {
    public GameObject explosion;
    public bool isDrone;

    public GameObject rotorToAnimate;

    void Start () {
    if (!isDrone) {
    ExploderSingleton.ExploderInstance.ExplodeObject (gameObject);
    Instantiate (explosion, transform.position, Quaternion.identity);
    Destroy (gameObject,30f);
    } else {
    GameObject.Find ("Exploder Drone").GetComponent<ExploderObject>().ExplodeObject(gameObject);
    Destroy (gameObject,15f);
    }
    }
    }

    Any help/advice would be greatly appreciated!
     
  48. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    315
    I found a bug where calling ExplodeObject() would often immediately delete all existing fragments. I tracked it down to FragmentPool.Allocate where you use "useMeshColliders != this.meshColliders"
    For now I worked around this by always using mesh colliders.
    At a minimum there should be a Debug.LogWarning() when you do this
     
  49. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    Hi, still having an issue with having too many meshes in the mix when it explodes. It looks like it duplicates the mesh twice and explodes both of them. I'm cracking the individual objects with their own exploder objects using void CrackObject (GameObject) and calling void ExplodeCracked (GameObject).
     
  50. reindeer-games

    reindeer-games

    Joined:
    Mar 5, 2013
    Posts:
    547
    Hi!

    Cool game by the way! Exploder can be processing few frames if the mesh is complex or the number of fragments is too high. If you want immediate explosion, you can use "crack" feature, more info in docs:

    https://docs.google.com/document/d/...a9ZJvjwtl7bU/pub?embedded=true#h.ozdfi95wq4wq