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. Dismiss Notice

Destructible 2D ☄️ Dynamic Sprite Destruction

Discussion in 'Assets and Asset Store' started by Darkcoder, May 29, 2014.

  1. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    thank you very much
     
  2. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    i think there is a bug on the new diffuse shader, check the image, that flat grey ground it is a little bit transparent, if i swap to Sprites-Default(Destructible2D) shader it becomes solid, the weird thing is it only happens on this ground sprite, i have other sprites using the Diffuse shader and they look ok , but i have revised everything a thousand times , i don't know what could it be, the only thing this sprite has different to the others is the alpha text has been generated by Destructible Sprite script, on the others i have replaced the alpha texture by a custom one i made in photoshop so it could be something related to the alpha texture generation that only seems to be noticeable on the difise shader? just thinking loud...
     
  3. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    some more info: i was wrong, the problem also happens with Sprites Default D2D shader, but then i fixed it by deleting the entire game object and creating everything again , anyway i think there could be a bug in the alpha texture generation code
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    It's possible the AlphaTex generation code (which uses Texture2D.GetPixel) isn't compatible with certain texture formats, for example if you use AutomaticCompressed then I believe GetPixel won't work. Can you tell me the texture format used for that sprite?
     
  5. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    right now i am using RGBCompressed DXT5 and its working , the read write flag is enabled and i think i dint marked it, so it think it was destructible code who did it when creating the destructible sprite, i have changed the compression many times also because another issue i will post later, anyway i don't think i have changed the compression when i recreated the entire game object and before was not working but now it does...
     
  6. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    hey , is there any reason colliders generated by DestructibleSprite get localPosition.z = 1
     
  7. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    hey , is there any reason colliders generated by DestructibleSprite get localPosition.z = 1
     
  8. zawrot13

    zawrot13

    Joined:
    Mar 29, 2015
    Posts:
    1
    Hi, The plugin is great and I'd like to buy it....but....there is one big problem. I tried to compile the demo on plenty android devices and there are some of them where the destructible objects are not visible !!! One important example is Samsung Galaxy TAB model: GT-P3100. Every sprites changed to destructible are not visible. Coliders are working and looks like even whole fracturing processes working well but the objects and the parts are not visible. Do You know where the problem could exist? Is it the material issue?
     
  9. StartUpStudios

    StartUpStudios

    Joined:
    Jul 14, 2013
    Posts:
    11
    Any chance I could get a demo? I am wanting to make a game idea I have, and am not quite sure if this would do everything I need. I'm not planning on selling the game, so can't swing for a $50 asset that might or might not work for what I need. Maybe just the explode portion so see if itll function for the core mechanics?

    What i'm wanting to use it for:
    Randomly generated terrain (possible with this tool? Would I have to generate the mesh some other way first?)
    My character would then blow his own path through, underground, using various weapons. From what I've seen that's completely possible with this.
    What about randomized explosion patterns? (Maybe you mentioned that somewhere but I haven't read the whole thread)
    What about carving out a hole in the mesh for items (i.e. Large unbreakable boulders that would fall if what's below them gets blown away?)

    Thanks for your time. -M
     
  10. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Dammit, this forum's notification system man!

    Your source destructible sprite must have a Z position of 1, or be a child of a GO that has this position. I just tested it out and split children get a Z position of 0, but if I set the parent to 1, and then split, the children get 1 as well.


    There's a demo? If you tell me which shaders you tried then I can investigate. Also, I modified the shaders in the latest version, so that might have fixed things.


    There's no official demo for D2D. I've considered making a cut down version in the past, but every user wants to try a slightly different aspect of the feature set, so there's no one demo I can make that will be useful for everyone without giving away all the code.

    - D2D has no terrain generating abilities, but if you create a terrain texture and turn it into a sprite, then you can easily turn that static sprite into a destructible one.

    - Yes, if you generate a basic terrain texture and make it destructible, then you would be able to dig through it and such.

    - There are no randomized explosion patterns. However, if you create a small selection of different explosion and shapes and randomly rotate & scale them when you place the explosion, then you can easily give the illusion of unlimited destruction shapes.

    - Falling boulders and such are possible using a variety of methods. The simplest method is to just cut a hole in your terrain, place a boulder there, attach a rigidbody to your boulder, and it should naturally fall when the user digs out enough terrain below it. Another approach is to suspend the boulder in the terrain until some trigger is activated, then the boulder begins falling through the terrain and finally activates once it leaves the terrain's collider (so it doesn't get stuck).
     
  11. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331

    Hey guys, Destructible 2D 1.1.5 is now out.

    I've moved the main build to Unity 5 (though the 4.5.0 build is still accessible), so you should no longer see that import warning if you're using Unity 5, and it also allows me to do some new things.

    The most important of those new things is that I replaced the destructible sprite material system with the PerRendererData approach that was actually in the first version of D2D, but was removed due to a Unity bug that's now been fixed. This change means that you no longer have to specify the 'Source Material' in the D2D_DestructibleSprite, and that the SpriteRenderer itself is not modified with a cloned material when you make it destructible. This increases performance for scenes with many destructible sprites, and increases compatibility with other sprite shader systems!

    Also, I'd like to thank Daniel Manzano for helping me optimize the code. He found some areas where I needed to optimize things, and the sprite stamping code should now be several times faster than what it was before!
     
  12. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    that's me ! LOL glad to help to improve this fantastic asset !
     
    Darkcoder likes this.
  13. abatcat

    abatcat

    Joined:
    Feb 8, 2015
    Posts:
    70
    DrKucho did you manage to get it to work with light2d?
     
  14. DanielKhoroshko

    DanielKhoroshko

    Joined:
    Mar 11, 2015
    Posts:
    9
    Hi

    Would D2D work with 2D Toolkit sprites?

    Thanks
     
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Nope, it uses Unity's 4.6+ sprite system, including the 4.6+ 2D colliders.
     
  16. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    not yet, im talking to light2D developer, he does not believe is a D2D incompatibility but i am 99% sure, it works when i use normal sprites so it has to be the reason i said.
     
  17. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    Darkcoder

    i have modified your code so much so it's gonna be dangerous to update to the new version right now, but the new fix about "destructible sprite material system with the PerRendererData approach" might be the solution for another incompatibility i have now with Light2D asset , could you be specific about which parts of the D2D code were modified just for this material thing so i can maybe import and readapt only these scripts and keep the others i have modified ( D2D_PolygonSpriteCollider, D2D_ColliderBuilder, D2D_DestructibleSprite, D2D_Destructible)
     
  18. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    If you download the new package then you can diff the files to see what was changed. But mainly it's the OnWillRenderObject method, as well as removing the parts of code that cloned the 'SourceMaterial' field.
     
    DrKucho likes this.
  19. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    I've got news about D2D and Light2D incompatibilities, check Light2D thread for details
     
  20. abatcat

    abatcat

    Joined:
    Feb 8, 2015
    Posts:
    70
    Thanks, really hope you'll get it to work :)
     
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Hey guys, Destructible 2D is currently in the I ♥ 2D Sale!

    Please spread the word!


    >>> GET IT NOW <<<
     
  22. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Hey there, just bought it on sale and I think it is awesome!

    Could you update tutorial on youtube though? I have noticed that some things have changed.

    Advanced video tutorials would be nice aswell! :)
     
    Last edited: Jun 16, 2015
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Thanks, I've been meaning to make more videos for it, I should have some free time this weekend. I also have some ideas for things to add to the next version :)
     
  24. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Can you share these ideas with us? :)
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Yes, a user just asked me how to undo damage on sprites, and it occurred to me that the sprite cropping optimization I added to an earlier version limits the ways you can undo things (e.g. you can't always paint parts of a sprite back). So I had the idea to make some way to expand the cropped area if you use a negative destruction stamp. I also noticed I missed a few parameters in the ReplaceAlphaTex methods, so you can't always revert sprites back to a previous damage state correctly (except for the initial state).
     
  26. haim96

    haim96

    Joined:
    May 24, 2013
    Posts:
    107
    hello,

    i just bought this asset and it's really amazing!
    i didn't finished to check all the scripts but i wonder, is there a way to reset a sprite that had damage (with\without split)
    in run time to it's initial state without instantiate new sprite?
    in case i want to recycle sprites with object pool or something like this.... thanks!!
     
  27. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Hey I have a problem, when building scripts it says that Default parameter specifiers are not allowed, from your code. How can I fix it?
     
  28. josessito

    josessito

    Joined:
    Feb 14, 2014
    Posts:
    57
    Hi, I'm hoping to by this asset but I have a question first. What would happen if the GameObject that has the sprite renderer also have an animation component or other scripts., and you split it. Will the new parts will also have this components or they would be just a sprite?
    Thanks!
     
  29. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Just set the AlphaTex property to null and it will be reset to its original state.


    For which platform? Which version of Unity? I was under the impression this was fixed for iOS a long time ago, and wasn't an issue for most of the others.


    When a sprite is split it is duplicated using Instatntiate and then the new AlphaTex (destruction shape) data is applied to each so they look different. This means your original components and hierarchy will be preserved.
     
  30. evil-tediz

    evil-tediz

    Joined:
    Aug 31, 2013
    Posts:
    1
    Hi,

    does Destructible 2D generate the colliders at runtime? If I create a procedural texture at the start of the game will it automatically create a collider?

    Thanks!
     
  31. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Yes. But there's no way to detect when a Texture2D has been modfied, so you might need to manually call the method to recalculate the colliders for the texture.
     
  32. haim96

    haim96

    Joined:
    May 24, 2013
    Posts:
    107
    ok, and then what? does AlphaTex recreated when the object got damage again?
    or do i need to set it to something else before it spawn again?

    also, how should i handle split object with pooling if split object instantiate new object?
    can i replace the instantiate function with object pool spawn and despawn?

    thanks!
     
  33. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Setting it to null will cause the alpha data to be read from the original sprite again, thus resetting any damage done.

    Indeed, you should be able to replace the Instnatiate with some pooling method as you mention, just be very cautious about how you're pooling things, because typically each destructible sprite is quite different in terms of collider scripts and other stuff, so you wouldn't be able to mix and match them.
     
  34. haim96

    haim96

    Joined:
    May 24, 2013
    Posts:
    107
    but if i pool and spawn from the same prefab it should be OK, no?
     
  35. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    In most cases, yes.
     
  36. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    838
    To bad this doesn't work with 2D tool kit, otherwise I would of bought it.. Looks good otherwise keep up the good work.

    PS: Not a fan of Unity's 4.6 2d tools. I have grown to love 2D tool kit.
     
  37. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Windows with Unity 5.1.0f3 (64-bit)
     
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Works fine for me when building the example scenes using Unity 5.1.0f3 for Windows x86_64. Maybe you can give me incredibly specific step by step instructions on how to replicate this from a fresh project with just D2D?
     
  39. Giosolo

    Giosolo

    Joined:
    Sep 19, 2012
    Posts:
    8
    Hi,
    I would like to know whether this toolkit supports NGUI sprites.

    Thanks
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    No, it only supports the built-in Unity SpriteRenderer.
     
  41. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Create new 2D Project.
    Click open in unity from asset store.
    Click import.
    Import everything.
    Create empty gameobject.
    Add new script to it.
    Open in monodevelop.
    F8 to build.
    23 errors, first at DrawText at D2D_Tooltip

    Whats weird is that the game runs and scripts work from it, but it doesn't show me what errors I have made in code (from monodevelop) since it automatically shows errors in yours.
     
    Last edited: Jun 18, 2015
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    I see, it looks like it's an issue with the way the default solution is set up. I personally only use Unity to compile it, and I've never encountered any issues with this. To fix it you apparently have to force monodevelop to compile using .NET 4.0, which can be done manually or via script it seems, just check the first few results in google when searching for that error.
     
  43. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Thanks, I will look into that.

    Let us know when you make the tuts, can't wait! :)
     
    Darkcoder likes this.
  44. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    After playing a while on empty projects I decided to try and integrate it into mine, but I'm getting this:
    It is worth mentioning that I have set custom material for my sprite. I need it for normal mapped 2d lightning.

    Is there a way to work around this?
     
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    You need to modify your custom shader to support the D2D features. See the 'Custom Shaders.pdf' documentation on how to do this. You can also look at the D2D shaders to see how it was implemented in those.
     
  46. Nitugard

    Nitugard

    Joined:
    May 10, 2015
    Posts:
    340
    Hi,

    Is there any way to change or reset alpha texture?
    I tried storing byte array of the alpha texture(alpha data) at the beginning of the game and then setting alpha data to old one. But I just can't get it to work.

    I did managed to reset alpha texture by using ReplaceAlphaWith(Texture) but I think that this is much slower? Isn't it?

    Thanks,
     
  47. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    Set it to null and it will revert to its original state.
     
  48. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Custom shader is in cg and your instructions are for glsl/hlsl I believe, I don't know cg so I can't do much here :(
    Would it be too much to ask you to modify the standard shader for me? I would be really thankfull.
     
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,331
    The documentation is all in cg.

    If you can find an example of a sprite standard shader then I can modify it, but Unity only comes with an unlit and diffuse one (D2D comes with variants for both).
     
  50. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    I'm including Standard.shader and cginclude folder which has all the includes (I hope) that Standard.shader uses.

    I'm creating custom material, selecting standard shader, applying normal map to it, then dragging it on sprite and adding standard lightning to the scene.

    I wish I could give you 10 stars for support, I guess I will have to stick to 5 ;)