Yes, your destructible object can have a different collider and visual shape within reason, and you can also trigger collisions from code at any time.
The biggest performance bottleneck is just using collider data that is too detailed, but this can easily be reduced using the built-in ‘Optimize Alpha’ setting, which halves the width & height of the destructible data and smooths the edges to make it look similar, making everything 4x faster.
Hi, I love your plugin - it works pretty well. I do have some performance issues - at the moment of instantiation there is a noticeable “hiccup”. I managed to reduce this by using the “Optimize Alpha” feature on the Destructible element. When I do this, however, I get an error when running - “Destroying assets is not permitted to avoid data loss.” This is coming from the following calls:
Destroying assets is not permitted to avoid data loss.
If you really want to remove an asset use DestroyImmediate (theObject, true);
UnityEngine.Object: Destroy(Object)
Destructible2D.D2dHelper: Destroy(PolygonCollider2D) (at Assets/Destructible 2D/Scripts/D2dHelper.cs:35)
Destructible2D.D2dPolygonCollider:Sweep() (at Assets/Destructible 2D/Scripts/D2dPolygonCollider.cs:133)
Destructible2D.D2dPolygonCollider:OnStartSplit() (at Assets/Destructible 2D/Scripts/D2dPolygonCollider.cs:111)
UnityEngine.Events.UnityEvent:Invoke()
Destructible2D.D2dDestructible:Split(D2dSplitGroup, List`1, Int32) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:1312)
Destructible2D.D2dQuadFracturer:Fracture(D2dDestructible, Int32, Single, Int32) (at Assets/Destructible 2D/Scripts/D2dQuadFracturer.cs:88)
When I revert the object back to the way it was before using “Optimize Alpha”, the error does not occur.
Do you have an idea of how to avoid this?
Also, a feature I could use is the ability to set the instantiated clones’ layer to something different from the parent destructible (including the layer of the remaining fragment, which is not a clone - which was the parent object). I’d also like to be able to set the clones’ mass. Could you add the ability to be able to modify these?
Are you trying to call Optimize Alpha on a prefab? If so, you need to drag it into your scene, modify it, then apply the changes back to the prefab. If not then I’d like some steps to reproduce the issue.
The features you mention are possible to implement, but I don’t think many people would find them useful, so it’s best if you modify the D2D code to work how you want. You can see the layer setting code for splitting on line 1346 of D2dDestructible.cs, and you can look at the D2dRetainVelocity script to see how you can hook into the OnEndSplit event to modify split rigidbody information.
Hey there, awesome plugin you’ve got here. I was just wondering if there is any way to optimize it further, other than the optimize alpha option? I’m running about 200(preferably more) objects that have a repeat stamp on them, with a custom script to iterate over the stamp running to distribute the load more.
Also, the collider generation seems to not play too well with triangles.
And while I’m here, there was a bug with an edge collider on a 1280pxX256px image, where it would cause lag if a certain collider was hit, even by a single object. Same thing was generated each time I tried to make a destructible from that image. I checked it over, didn’t seem to be any extra colliders out of place, but one or two of them were causing some kind of issue.
200 repeat stamping objects is pretty extreme. The best way I can think of to optimize that scenario is to only stamp if the stamp or some object in range has moved. Additionally you could stop or reduce stamp frequency on objects that aren’t in the camera view. If it’s still slow then you can try changing the stamp code to only mark edited pixels as modified, because right now it marks the whole stamp rectangle, which may not actually contain any changes. I didn’t test if doing this would be faster in all scenarios though.
I’m not really sure what I’m looking at in this picture. Is the generated collider twice the size it should be? If so, could you e-mail or message me a simple UnityPackage containing a scene with just that broken object so I can test?
Assuming your edge collider wasn’t being modified during this lag then it sounds like an issue with how detailed that particular collider was. Did you check the point count in the inspector to see if it’s something crazy compared to the others? You can try decreasing the collider detail to see if it improves it. If the shape isn’t the issue then I have no idea, as D2D doesn’t do anything after the colliders have been generated.
Yes, SpriteRenderer is basically the same as MeshRenderer, so sprite shaders will work, and they can render together. However, D2D requires a few additional tweaks to the shader to show the destruction. There is a pdf that comes with D2D that details these modifications.
Hi, please provide instructions on how to use this with meshes…
I have a procedurally generated mesh at runtime that has vertices and triangles array.
How to feed this information to Destructible 2D ?
You can render your mesh using a Camera that has a RenderTarget, and copy the rendered pixels into a normal Texture2D, and then you can call yourD2dDestructible.ReplaceWith(yourTexture2D) to make it destructible.
Switched to iOS it said the texture not supported in Unity 5.4.0 as:
Unsupported texture format - needs to be ARGB32, RGBA32, BGRA32, RGB24, Alpha8, RGBAFloat, RGBAHalf or one of supported compressed formats.
UnityEngine.Texture2D:GetPixel(Int32, Int32)
Destructible2D.D2dDestructible:SampleStamp(Texture2D, Vector2) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:744)
Destructible2D.D2dDestructible:Stamp(Matrix4x4, Texture2D, Single) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:652)
Destructible2D.D2dDestructible:StampAll(Matrix4x4, Texture2D, Single, Int32) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:552)
Destructible2D.D2dDestructible:StampAll(Vector2, Vector2, Single, Texture2D, Single, Int32) (at Assets/Destructible 2D/Scripts/D2dDestructible.cs:535)
Destructible2D.D2dExplosion:Start() (at Assets/Destructible 2D/Examples/Scripts/D2dExplosion.cs:99)
It doesn’t help even I change the Main Tex in D2dDestructible Format to Truecolor, it seems to be the problem of the Alpha Tex the script generated in run time. Any quick fix?
I don’t use Playmaker, but I believe it has the ability to modify normal component fields and call methods, so they should work fine together. The fields and methods have the same names as in the inspector, so if you figure out how to do something in the inspector then it should just be a case of doing the exact same things from your FSM.
Does it work with a game object that has an animator and shows a couple of sprites taken from a spreadsheet?
Is it able to destruct the whole game object or only applies to a single sprite?
I saw a demo where the player can destroy a Bee that seems animated, unfortunately the Bee stops flying when hit. I don’t understand if the damage can be inflicted to all sprites of the Bee or only one sprite.
There are two ways you can animate things in D2D using the Animation/Animator features:
1 - Create multiple destructible objects and combine them together into a compound destructible object. e.g. make an empty parent gameObject and attach a bunch of different body parts that move around.
2 - Replace the base texture for the destructible object, e.g. the bee example.
Keep in mind that 2 works best if your object shape doesn’t change while animating. You’ll notice the bee’s wings move as it animates, so I had to combine all the animation frames to use as the collision shape, otherwise the wings would disappear as they go behind the original collision shape/mask.
Two questions: is there a good approach to making sprites? I’ve more than once come across sprites that have an alpha count of 400k - when fracturing these my PC died When using 15k, the fractures look kinda rugged and not crisp. I’ve noticed that if I use 50k as alpha count it looks ok but fracturing is already quite laggy (0.5s delay or something).
Secondly: can you destroy a sprite partially? For example, if I make a planet sprite, can I break off part of the planet by fracturing? I know stamping/slicing can do it but I kinda want to ‘stamp’ around the impact point of an asteroid and fracture the part of the planet that falls under the stamp (so to speak).
Thank you for the answer.
During the night I changed the “animation approach”. I will resort to make the animation in the Update method simply swapping sprites. So I can apply the solution described in bullet 2, right?