Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shatter Toolkit

Discussion in 'Assets and Asset Store' started by gustavolsson, Jul 8, 2011.

  1. dreadt9

    dreadt9

    Joined:
    Jan 13, 2012
    Posts:
    143
    You did a very good job, one thing that would get you a lot more buys is if you lowered the price a lot more.
     
  2. Jum

    Jum

    Joined:
    Aug 20, 2011
    Posts:
    63
    I have tried the webplayer demo. Its really good. I was looking for something like that. But need something more. There is a skinned character which i will split from different joints(upper arm, forearm, legs knee,etc) is it a supported feature?
     
  3. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Gustav,

    I've altered ShatterTool.cs in order to get more performance for mobile. My basic idea was to precompute the shatter effect by calling the Shatter method during StartUp and passing in a Vector3.Zero instead of having that occur at runtime upon collision. This reduces the computations occurring at runtime so I can have a lot more shatters. I turn on and off the renderer and colliders of the original object and the clones resulting in a similar effect.

    Although I lose the accuracy of the breakup occurring at the contact point, I make up for that by applying an explosion force at the point of collision during runtime and the end result looks basically the same. But one big problem I've run into is when you run the Shatter method from StartUp passing in Vector3.Zero, you get a large variance in the number of resulting newHulls/clones. I frequently even see just one clone being created. Yet when Shatter is called during runtime, as it is designed, you get a predictable number of clones based up the Cuts you set.

    Do you have any suggestions as to why this would make a difference?

    Thanks
    Allan
     
  4. lastprogrammer

    lastprogrammer

    Joined:
    Apr 30, 2011
    Posts:
    166
    Hi, I love this toolkit and have games on iOS that feature it prominently. I want to know how I can use a different material when the mesh is cut up. I am using the Target UV Mapper component so that I can use a specific part of the current material to use on the cut mesh, but I was wondering if there is a way to use a different material all together for the cut mesh.

    Thanks.
     
  5. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Thanks! While I don't plan to lower the price permanently, I might have a sale in the future.. Perhaps if there is another Asset Store Madness :)

    Hm, sounds strange. Make sure that you specify the shatter point in world space and at the center of the object to be shattered. In order to shatter the object at it's center, use rigidbody.centerOfMass as shatter point if you use rigidbodies (this will split the pieces at the center points too, if shattered), otherwise use transform.position.

    Passing Vector3.zero will shatter the object in planes passing through the origin of the world, which will not look especially nice unless the object is large or close to the origin.

    No, the toolkit does not support skinned/animated meshes and never will, sorry. It is a deliberate choice on my part :)

    You can toggle the PostSplit(GameObject[] pieces) message in the inspector for the ShatterTool and then create a script that catches that message and replaces the materials of all the new pieces :)

    Hope this helps, thanks for the feedback everyone!
     
    Last edited: Apr 25, 2012
  6. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    I'd be interested too if there is a sale on it.
     
  7. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Gustav,

    I tried all of your ideas:
    Just as a test, I'm using the Walls Demo scene.
    I choose the center cube and set the generations to 2 and the cuts to 4. I removed the ShatterOnCollisions component from this cube.
    I place the call to the Shatter method in Startup in ShatterTool.cs after the Hull == null check if statement.
    That's it. I tried passing all of your suggestions into the Shatter method. I am using rigidbodies on my objects.

    Here are my results with each method call from StartUp after numerous runs using each method.

    Shatter(gameobject.rigidbody.centerOfMass); results in 2 - 10 clones randomly
    Shatter(gameobject.transform.position); results in up to 14 clones randomly
    Shatter(gameobject.transform.localposition); results in up to 14 clones randomly

    It appears either Cuts or the Validation check in Hulls.cs is acting differently when you call Shatter from StartUp vs runtime.

    Are you doing any other precalculations anywhere in StartUp that I'm not aware of that perhaps are not completing when I cal Shatter? That's the only thing I can think of.

    Thanks for any more help.
    Allan
     
  8. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Oh, sorry, I meant that you should use the rigidbody.worldCenterOfMass property!

    Instead of modifying the ShatterTool.cs file (which I don't recommend) I created a new script called ShatterAtStart.cs that executed after the shatter tool (use the Execution Order dialog for this):

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. [RequireComponent(typeof(Rigidbody))]
    5. public class ShatterAtStart : MonoBehaviour
    6. {
    7.     void Start ()
    8.     {
    9.         SendMessage("Shatter", rigidbody.worldCenterOfMass);
    10.     }
    11. }
    12.  
    This will almost always result in (GenerationLimit * Cuts) number of pieces. (very thin game objects are not instantiated)

    I plan to add a ShatterTool.WorldGeometricCenter property in a future update that will enable you to do this without having a rigidbody attached, if you don't need it for physics :)

    Hope this helps!

    By the way, this is a really neat trick :) Even though the game object won't be shattered at the impact point as you say, we can change how "chunk-like" the resulting pieces will be by changing the GenerationLimit/Cuts ratio. Thanks for pointing it out!
     
    Last edited: Apr 26, 2012
  9. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Gustav,

    This appears to work :) however the ShatterAtStart script executes on every clone thus sending numerous SendMessages as soon as they are instantiated....not so great for mobile....depending on the number of shards you are creating. I solved this by grabbing a reference to the ShatterAtStart script, checking if it is null and disabling it when the newGameObjects are created in the CreateNewGameObjects method in ShatterTool.cs. There's probably a better way to do this. If I could detect if the gameobject was a clone, then I could disable ShatterAtStart before it executes the SendMessage. But I'm not sure how to do that.

    So this works:) but I still think it would be cleaner if you could place the call to the Shatter method in Startup of the ShatterTool.cs. But of course this would mean that other Startup executions would have to be complete. My guess is Hull.cs is still running stuff even though you call the Shatter method after the hull = new Hull(GetComponent<MeshFilter>().mesh); statement.

    I've never used lock (key) in C# before but since it appears to have something to do with threading, my ignorant guess is it's allowing Hull.cs to keep working even after hull = new Hull(GetComponent<MeshFilter>().mesh); is executed.

    Allan
     
  10. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    That's what the Generation property of the ShatterTool is for :)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. [RequireComponent(typeof(Rigidbody), typeof(ShatterTool))]
    5. public class ShatterAtStart : MonoBehaviour
    6. {
    7.     void Start ()
    8.     {
    9.         ShatterTool shatterTool = GetComponent<ShatterTool>();
    10.  
    11.         if (shatterTool.Generation == 1)
    12.         {
    13.             SendMessage("Shatter", rigidbody.worldCenterOfMass);
    14.         }
    15.     }
    16. }
    17.  
    (As I said before, I really don't recommend modifying the ShatterTool.cs or any other source file that comes with the toolkit, use external scripts like the above instead :))

    Note about the lock keyword in the internal source files: The lock is indeed for multithreading, even though the toolkit is singlethreaded. I experimented with a multithreaded version earlier in the development cycle but decided not to use it. (There is no standard way of doing multithreading in unity, the benefits were not great etc)
     
    Last edited: Apr 26, 2012
  11. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Gustav,

    Thanks that worked great! :)

    Allan
     
  12. Ulven2

    Ulven2

    Joined:
    Apr 23, 2012
    Posts:
    64
    Hi, I bought this yesterday.
    I've been experimenting for a while to get it to run efficiently in my project.
    I have a sphere mesh consisting of 180 tris which has a mesh renderer (diffuse, no map), a rigid body, a constant force, a shatter tool, a world uv mapper, a sphere collider, and a script that I'm using to send the fracture message on.
    The fracture script is just this (in boo):
    def OnCollisionEnter(collision as Collision):
    SendMessage("Shatter",transform.position)

    Even using this, and only 2 shatter planes, it looks like I miss out on about 0.2-0.4 or so seconds of time before the frame is refreshed on an ipod touch 4g. As it's an 'action' part of the game this is highly visible (as opposed to the relatively static example files)
    Is there something else I can do to optimize your code for mobile, something I'm doing wrong, or is it just not possible to do dynamic fracture on mobile?
    (The rest of the game is running completely fluently until I add this)

    EDIT: There is even a visible hickup when I run it directly on my macbook air.
     
    Last edited: Apr 27, 2012
  13. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Nice!

    Is there a reason why you don't use the bundled ShatterOnCollision script? What is the generation limit set to?

    Since your script shatters the game object as soon as there is a collision, the resulting pieces will also be shattered as soon as they're instantiated because they're colliding (and so on until the generation limit is hit), which will be too slow for practical use. This is why the ShatterOnCollision script has a required force property and a cooldown timer :)

    For mobile platforms I suspect only very low poly meshes are practical and 180 triangles might be too much in this case. However, try replacing your script with the bundled ShatterOnCollision script and see if it helps. (The ShatterOnCollision script also uses the point of collision to shatter the game object, which should look better)

    Related note: If you are using sphere colliders, you should probably scale the radii of the resulting pieces down using a script (use the PostSplit() message of the ShatterTool). I will add an example scene showing how to do this in the next update. Unless this is done, the sphere colliders of the pieces will almost always collide when created and send the pieces flying violently. Convex mesh colliders are the easiest way to avoid this problem, but are slower performance wise.

    Hope this helps!
     
    Last edited: Apr 27, 2012
  14. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I've submitted an update to the toolkit that I've been working on for the past few weeks. I wanted to improve the performance of the toolkit and I managed to increase it by 20-50% for my test meshes. It is now possible to switch shatter algorithm and the new algorithm is simply called FastHull, whereas the old algorithm is called LegacyHull. The LegacyHull is provided for backwards compatibility since it is more robust in extreme cases.

    Here is the change list:

    • Added an improved shatter algorithm which is 20-50% faster than the legacy algorithm and requires no time at startup
    • Added the ability to easily switch between the new and legacy algorithm (for backwards compatibility)
    • Added the ShatterTool.Center property which can be used to get the approximate world space geometric center of a game object
    • Added the HierarchyHandler helper script which makes it possible to use the ShatterTool script within game object hierarchies
    • A few small bug fixes


    The update should be live as soon as Unity accepts it, I hope you like it!
     
    Last edited: Jun 26, 2012
  15. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Version 1.2 of the toolkit is now released! See the above post for the change list.

    I also uploaded a new webplayer demo to reflect the new features/optimizations made in the toolkit.
     
  16. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    In the new update I'm unable to get the shatter on collision to work properly. Before when I had shatter on collision, world uv mapper and shatter tool on an object they would shatter on collision no problem. Now under the same setup the shatter message is getting sent from the shatter on collision file but it's not getting received by the shatter tool. Any idea on what's going wrong?
     
  17. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    @wightwhale How is the game object hierarchy set up? I changed the ShatterOnCollision to always send a shatter message to the game object of the collider involved. This is needed for example if a root game object with a rigidbody has a child with a collider. If the child collider is hit, the rigidbody in root will trigger the OnColliderEnter message on the root, not the child. Thus, the new script will pick up the collision in root and try to shatter the child, since this is where the collider actually is.

    It should work the same for all standard configurations of game objects, but there might be something that I've missed so I would be grateful if you could describe your setup.
     
  18. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Oh ok that would be the issue then. In my setup I have a group of colliders as a child to the parent game object which has all the shatter toolkit scripts on it. Any idea's on how to rework this so I don't have to only have 1 collider on an object?
     
  19. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Ah, so you are only shattering the game object once then? (The colliders in the child game objects would no longer fit the pieces, right?) I did not think of this possibility and will update the script in the next update.

    Here is a quick mockup, replace your ShatterOnCollision script with the following:

    Code (csharp):
    1. // Shatter Toolkit
    2. // Copyright 2012 Gustav Olsson
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class ShatterOnCollision : MonoBehaviour
    7. {
    8.     public ShatterScheduler scheduler = null;
    9.    
    10.     public float requiredForce = 1.0f;
    11.    
    12.     public float cooldownTime = 0.5f;
    13.    
    14.     public bool shatterColliderGameObject = true;
    15.    
    16.     private float timeSinceInstantiated = 0.0f;
    17.    
    18.     public void Update()
    19.     {
    20.         timeSinceInstantiated += Time.deltaTime;
    21.     }
    22.    
    23.     public void OnCollisionEnter(Collision collision)
    24.     {
    25.         if (timeSinceInstantiated >= cooldownTime)
    26.         {
    27.             if (collision.impactForceSum.magnitude >= requiredForce)
    28.             {
    29.                 // Find the new contact point
    30.                 foreach (ContactPoint contact in collision.contacts)
    31.                 {
    32.                     if (contact.otherCollider == collision.collider)
    33.                     {
    34.                         // Shatter at this contact point
    35.                         if (scheduler != null)
    36.                         {
    37.                             if (shatterColliderGameObject)
    38.                             {
    39.                                 scheduler.AddTask(new ShatterTask(contact.thisCollider.gameObject, contact.point));
    40.                             }
    41.                             else
    42.                             {
    43.                                 scheduler.AddTask(new ShatterTask(gameObject, contact.point));
    44.                             }
    45.                         }
    46.                         else
    47.                         {
    48.                             if (shatterColliderGameObject)
    49.                             {
    50.                                 contact.thisCollider.SendMessage("Shatter", contact.point, SendMessageOptions.DontRequireReceiver);
    51.                             }
    52.                             else
    53.                             {
    54.                                 SendMessage("Shatter", contact.point, SendMessageOptions.DontRequireReceiver);
    55.                             }
    56.                         }
    57.                        
    58.                         break;
    59.                     }
    60.                 }
    61.             }
    62.         }
    63.     }
    64. }
    Just disable the "Shatter Collider Game Object" checkbox for the game object in question :)
     
  20. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Thanks, that code worked great!
     
  21. lastprogrammer

    lastprogrammer

    Joined:
    Apr 30, 2011
    Posts:
    166
    So I've had this kit for awhile now and i've made thousands of dollars from the iOS game I've made from it (check out Shatter Blox on iTunes). But now I am interested in optimizing my game for an even bigger setup and world. Whenever I shatter an object my draw calls increase dramatically, it seems to increase by one draw call per object cut. This is very difficult for iOS especially in larger worlds.

    I was wondering if you knew the cause of this and if it could be fixed. Because it doesn't seem to make any sense, if the same material is used for the cut objects then there should only be one draw call for all objects that share that same material, right?

    Thanks for your help.
     
  22. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Awesome! I'm happy that you're finding the toolkit useful :)

    Unity automatically batches visible game objects into a single draw call. Without batching, there would be one draw call for each visible game object. However, game objects are only batched together if the share the same material, have standard scale and are rendered using less than 900 vertex attributes. The shader used will determine how many vertices a mesh is allowed to have before it has to use a separate draw call. See this manual page for more information.

    The shatter toolkit adds the minimum amount of vertices needed to create the cut area (this is not true for triangles though), so there is no room for optimization in this regard. If you want Unity to batch more game objects into fewer draw calls, use a shader that only uses the bare minimum number of vertex attributes: the Position and Normal vertex attributes.

    Hope this helps,

    Gustav
     
  23. superlol

    superlol

    Joined:
    Dec 6, 2010
    Posts:
    10
    Hi!! I bought this amazing plugin some times ago and now I'm playing with it, I'm trying to convert the mouseSplit.cs script on javascript but without results :(...any help?

    Here is the cose

    Code (csharp):
    1. #pragma strict
    2.  
    3. var raycastCount : int  = 5;
    4.  
    5. //var scheduler : ShatterScheduler = null;
    6.  
    7. var started : boolean = false;
    8. var start : Vector3;
    9. var end : Vector3;
    10.  
    11.  
    12. function Start () {
    13.  
    14. }
    15.  
    16. function Update () {
    17.  
    18.     if (Input.GetMouseButtonDown(0)){
    19.    
    20.         start = Input.mousePosition;
    21.            
    22.         started = true;
    23.     }
    24.    
    25.    
    26.     if (Input.GetMouseButtonUp(0)  started){
    27.    
    28.         end = Input.mousePosition;
    29.        
    30.         var mainCamera : Camera = Camera.mainCamera;
    31.        
    32.         var near : float = mainCamera.near;
    33.        
    34.         var line : Vector3 = mainCamera.ScreenToWorldPoint(Vector3(end.x, end.y, near)) - mainCamera.ScreenToWorldPoint(Vector3(start.x, start.y, near));
    35.        
    36.         for (var i : int = 0; i < raycastCount; i++)
    37.             {
    38.                 var ray : Ray = mainCamera.ScreenPointToRay(Vector3.Lerp(start, end, i / raycastCount));
    39.                
    40.                 var hit : RaycastHit;
    41.                
    42.                 if (Physics.Raycast(ray, hit))
    43.                 {
    44.                     var splitPlane = Plane(Vector3.Normalize(Vector3.Cross(line, ray.direction)), hit.point);
    45.                    
    46.                     //if (scheduler != null)
    47.                     //{
    48.                         //scheduler.AddTask(new SplitTask(hit.collider.gameObject, new Plane[] { splitPlane }));
    49.                     //}
    50.                     //else
    51.                     //{
    52.                         hit.collider.SendMessage("Split", splitPlane, SendMessageOptions.DontRequireReceiver);
    53.                     //}
    54.                 }
    55.             }
    56.            
    57.             started = false;
    58.        
    59.     }
    60.  
    61. }
    I also bypassed the scheduler part cause I don't know how to add this task from the js :(

    Thanks a lot :)...
     
  24. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    if there is a Playmaker integration i will buy it :)
     
  25. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The shatter toolkit can be triggered using a SendMessage call which can be sent using this PlayMaker action, so they should work nicely together :)

    Attach a ShatterTool and UvMapper script to the game object and then send a message to the game object where the Method Name is "Shatter" and the parameter a Vector3 object indicating where you would like to shatter the game object.
     
  26. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Why do you want to convert the script to javascript? It seems unnecessary to me :) Your code looks alright but I can take a look at it tonight.
     
  27. CommunityUS

    CommunityUS

    Joined:
    Sep 2, 2011
    Posts:
    240
    I am getting ready to purchase your Shatter Toolkit and I notice there is some ability to "do something" after an object has been shattered/split. How far does this go? Can I easily attach a listener to the resulting shattered clones that would let the user click on the objects and do something? Or a timer to dump after a minute, or make them collidable and things of this nature. Basically interact with the shards post shatter just as freely as I could a normal game object. If so how is this done? thanks, looks great!
     
  28. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, since the pieces are just clones of the original game object (with a different mesh) you can either do something in the Start() method of a piece or in the PostSplit(GameObject[] pieces) of the original game object. Use the ShatterTool.Generation property to determine whether the current game object is a piece or not and of what generation it is. The original game object is generation 1, it's pieces generation 2, and the pieces of the pieces generation 3 and so on.

    You simply need to write a script that does something given a specific generation and attach it to the original game object (it will get carried over to the pieces):
    Code (csharp):
    1.  
    2. void Start()
    3. {
    4.     if (GetComponent<ShatterTool>().Generation >= 2)
    5.     {
    6.         RemoveAfterFiveSeconds();
    7.     }
    8. }
    Hope this explains it :)
     
  29. Ulven2

    Ulven2

    Joined:
    Apr 23, 2012
    Posts:
    64
    I got a weird bug with shatter tool recently, and to be honest I don't quite understand what is wrong. Shatter tool seems to get this ArgumentOutOfRangeExption. I only seem to get it when I've deployed it to the ios device. It works as expected in the unity editor. The thing that makes it particularly odd is that I haven't changed the code and it used to work on the device as well.
    JustFracture just sends this message when a condition is met:
    SendMessage("Shatter", fracture_point)
    fracture_point is a properly initialized Vector3 with a position determined by the script.
    Any idea what might be going wrong?

    Here's the error report,
    Code (csharp):
    1.  
    2. ArgumentOutOfRangeException: Argument is out of range.
    3. Parameter name: index
    4.   at System.Collections.Generic.List`1[UnityEngine.Vector4].get_Item (Int32 index) [0x0000c] in /Applications/buildAgent/work/51c26656ff47b7e8/mcs/class/corlib/System.Collections.Generic/List.cs:630
    5.   at Hull.AssignVertices (.Hull a, .Hull b, System.Boolean[] pointAbovePlane, System.Int32[] oldToNewVertex) [0x00034] in /Users/Ulven/unity_projects/Dropbox/conkers/Assets/Shatter Toolkit/Core/Library/Hull/Hull.cs:311
    6.   at Hull.Split (Vector3 localPointOnPlane, Vector3 localPlaneNormal, Boolean fillCut, .UvMapper uvMapper, .Hull a, .Hull b) [0x0004c] in /Users/Ulven/unity_projects/Dropbox/conkers/Assets/Shatter Toolkit/Core/Library/Hull/Hull.cs:236
    7.   at ShatterTool.CreateNewHulls (UnityEngine.Vector3[] points, UnityEngine.Vector3[] normals, IList`1 newHulls) [0x00033] in /Users/Ulven/unity_projects/Dropbox/conkers/Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:250
    8.   at ShatterTool.Split (UnityEngine.Plane[] planes) [0x0005e] in /Users/Ulven/unity_projects/Dropbox/conkers/Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:192
    9.   at ShatterTool.Shatter (Vector3 point) [0x00050] in /Users/Ulven/unity_projects/Dropbox/conkers/Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:164
    10. UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    11. UnityEngine.Component:SendMessage(String, Object)
    12. JustFracture:Update() (at /Users/Ulven/unity_projects/Dropbox/conkers/Assets/Scripts/JustFracture.boo:42)
    13.  
    14. (Filename: /Applications/buildAgent/work/51c26656ff47b7e8/mcs/class/corlib/System.Collections.Generic/List.cs Line: 630)
     
    Last edited: Sep 11, 2012
  30. Ulven2

    Ulven2

    Joined:
    Apr 23, 2012
    Posts:
    64
    Gah, this was my own fault. For anyone that might get the same problem, I had checked 'optimize mesh data' in the build settings. It seems this caused the mesh data to be jarbled when it came somewhere down the line of the shattering.
     
  31. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I'm hitting this error extremely rarely. Any idea what is causing it or how to catch the error so it doesn't crash my game?

    !"Adjacencies: found non-manifold mesh!"
    UnityEngine.MeshCollider:set_sharedMesh(Mesh)
    ShatterTool:CreateNewGameObjects(IList`1, GameObject[]) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:347)
    ShatterTool:Split(Plane[]) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:223)
    ShatterTool:Shatter(Vector3) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:189)
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    ShatterOnCollision:OnCollisionEnter(Collision) (at Assets/Shatter Toolkit/Helpers/Game Objects/ShatterOnCollision.cs:72)

    Adjacencies::CreateDatabase: can't work on non-manifold meshes.
    UnityEngine.MeshCollider:set_sharedMesh(Mesh)
    ShatterTool:CreateNewGameObjects(IList`1, GameObject[]) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:347)
    ShatterTool:Split(Plane[]) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:223)
    ShatterTool:Shatter(Vector3) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:189)
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    ShatterOnCollision:OnCollisionEnter(Collision) (at Assets/Shatter Toolkit/Helpers/Game Objects/ShatterOnCollision.cs:72)

    ConvexMesh::loadConvexHull: convex hull init failed!
    UnityEngine.MeshCollider:set_sharedMesh(Mesh)
    ShatterTool:CreateNewGameObjects(IList`1, GameObject[]) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:347)
    ShatterTool:Split(Plane[]) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:223)
    ShatterTool:Shatter(Vector3) (at Assets/Shatter Toolkit/Core/Main/ShatterTool.cs:189)
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    ShatterOnCollision:OnCollisionEnter(Collision) (at Assets/Shatter Toolkit/Helpers/Game Objects/ShatterOnCollision.cs:72)
     
  32. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    It would be cool if I could setup the shatter toolkit to have a pre made split so as not to spike as badly on low end mobile devices. Any ideas on how this could be implemented easily?
     
  33. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I'm getting a null reference in AssignVerticies in fasthull.cs It only shows up on my iOS devices and is causing things not to split. Any idea on what's causing it or how to make a workaround?

    a.AddVertex ( vertex, normals [ i ], tangents [ i ], uvs [ i ], out oldToNewVertexMap [ i ] );

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    at System.Collections.Generic.List`1[UnityEngine.Vector3].get_Item (Int32 index) [0x00000] in <filename unknown>:0
    at FastHull.AssignVertices (.FastHull a, .FastHull b, Vector3 pointOnPlane, Vector3 planeNormal, System.Boolean[] vertexAbovePlane, System.Int32[] oldToNewVertexMap) [0x00136] in FastHull.cs:148
    at FastHull.Split (Vector3 localPointOnPlane, Vector3 localPlaneNormal, Boolean fillCut, .UvMapper uvMapper, IHull resultA, IHull resultB) [0x00025] in FastHull.cs:74
    at ShatterTool.CreateNewHulls (.UvMapper uvMapper, UnityEngine.Vector3[] points, UnityEngine.Vector3[] normals, IList`1 newHulls) [0x00041] in ShatterTool.cs:286
    at ShatterTool.Split (UnityEngine.Plane[] planes) [0x0007e] in ShatterTool.cs:225
    at ShatterTool.Shatter (Vector3 point) [0x0006e] in ShatterTool.cs:192

    (Filename: FastHull.cs Line: 148)
     
  34. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I figured out the latest issue. If you check optimize mesh data option in the player settings and the shader on the object which you are shattering doesn't use a normal then all the normal information gets deleted.
     
  35. kevinseligmann

    kevinseligmann

    Joined:
    Mar 23, 2011
    Posts:
    68
    Hello Gustav,

    I'm amazed of how well your plugin performs, it's simply awesome. But I'm having a little problem with it.
    The objects that I need to shatter, are objects with rigidbodies, so whenever I slice an object it gets thrown the hell out, normally upwards. I thought it could be the collision happening when creating the new gameobject, and if that's the case I don't really know how to solve it.

    for the time being I solved it by applying a force like this, after creating the rigidbody on the new objects created:
    newRigidbody.AddForce(Vector3.down * 22, ForceMode.Impulse);

    Which is a horrible and temporary solution to the problem.

    Could you give me a little hand here? I would really appreciate it.
    Thanks very much!
     
  36. keithsoulasa

    keithsoulasa

    Joined:
    Feb 15, 2012
    Posts:
    2,126
    Looks cool , but I can't afford a 150$ asset...
     
  37. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    any discount for the holydays :)
     
  38. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The toolkit is now on sale at 50% off :)

    I just noticed this myself, Unity did not send me a heads-up.


    I've been very busy with exams the last couple of weeks but I will try to answer more questions on the forums during the holidays. Please contact me through my website if you encounter anything showstopping.
     
  39. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Hi Gustav,

    I just tried to run your 3 demos from the Google Play Store on my Nexus 7 and none of them would run. They all start up with a garbage logo then quit. Any idea why?
     
  40. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Probably because they were compiled using an old version of Unity android and/or old android sdk. I've built a better demo app that I'll finish and upload when I have a bit more time, so keep an eye out :)
     
  41. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Thanks to everyone who has bought the toolkit during the ongoing sale! Just reply to this thread or contact me through my website if you encounter any problems with it.

    I just submitted an update (1.3) that fixes a bug (see below) and improves the performance by up to 15% :) It should be live as soon as Unity accepts it.

    Since the toolkit is focused on dynamic splitting of meshes there is no built-in workflow for this. The implementation depends on how and when you want to specify the splitting plane.

    In order to split a mesh and save the resulting 2 meshes for later use, you may use the FastHull class directly. Pass the original mesh to the constructor and call the Split() method to get the resulting 2 "hull" pieces. Call IHull.GetMesh() to retrieve the mesh for each hull respectively and then just use these meshes whenever you need them at runtime. One thing to be aware of though is that the input to the Split() method is in local object space, not in world space. Hope this helps!

    See the answer to the quote below..

    This was indeed a bug and it should be fixed in the latest update. The toolkit now only requires a vertex position channel (in the mesh) to function properly and you can remove the normal channel. Thanks for notifying me about this! :)

    Hi again, I emailed you a reply regarding this issue (separate email conversation) but did not hear back, did you solve it?

    For others that have a similar problem: This happens when using bad-fitting colliders and rigidbodies. Whenever a game object is shattered, the new pieces will intersect and the physics engine will fling them away from each other quite violently. Use convex mesh colliders to better represent the physical object or do some magic on the dimensions of the new colliders using a custom script to solve the issue.
     
    Last edited: Dec 25, 2012
  42. Mickman

    Mickman

    Joined:
    May 9, 2012
    Posts:
    153
    Hi all,

    I just finished reading over the thread... nice bit of kit for splitting atoms ;)

    I think I've come in at the right time, yes... 50% off Yipee to me :)

    One question. would it be possible to use this in conjunction with the Buoyancy asset .. for example I might have an ice berg that splits into more ice fragments.. I'm designing iOS apps.. sure hope this will work.

    Merry Xmas,

    Mick
     
    Last edited: Dec 26, 2012
  43. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The toolkits work well together but keep in mind that they're both quite performance intensive. I don't think the performance will be good enough on iOS devices unless you limit the the number of times a game object may be split to 1-2 and set the buoyancy quality to low.

    One thing you may want to do is to reset the non-fluid rigidbody drag values of all buoyant objects to be shattered. If this is not done, the pieces may spawn submerged and use the drag value of the fluid when not submerged. Use the following script to do this:
    Code (csharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4. [RequireComponent(typeof(BuoyancyForce))]
    5. public class ResetDragAtStart : MonoBehaviour
    6. {
    7.     public void Start()
    8.     {
    9.         BuoyancyForce force = GetComponent<BuoyancyForce>();
    10.        
    11.         force.NonfluidDrag = 0.0f;
    12.         force.NonfluidAngularDrag = 0.0f;
    13.     }
    14. }
    Another thing to note is that I'm currently working on an update for the buoyancy toolkit that will fix a rare bug that you may run into while combining the toolkits. It occurs whenever a very skinny object is using a buoyancy force with a low number of samples (ie. a low quality setting). So, keep a look out for the bug and stay tuned for the update if you happen to encounter it. (AddForceAtPosition will fail within the BuoyancyForce script)

    If you decide to take the plunge, please let me know how it performs in your scenario :)
     
  44. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Does the shatter toolkit work with skinned meshes?
     
  45. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The toolkit does not support animated/skinned meshes. This was a decision I made early on and I don't plan to add support for it in the future. I'll add this question to the FAQ at the website, thanks!
     
    Last edited: Dec 26, 2012
  46. Zozo2099

    Zozo2099

    Joined:
    Jul 15, 2012
    Posts:
    478
    Please can I know if it is compatible with Unity 4?
     
  47. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The update is now live on the asset store :)

    Yes!

    Some of the example scenes in the toolkit has meshes without texture coordinates while using shaders that require it though, and for some reason that generates a lot of warnings in Unity 4 on my windows machine. These warnings lowers my framerate a lot, but as soon as I change the materials to fit the mesh, everything is fine. So if you get the same slow-down in some of the example scenes, just change the material or assign a texture and it should work fine. (It has nothing to do with the toolkit)
     
    Last edited: Dec 30, 2012
  48. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I just submitted another update for the toolkit (1.4) that improves performance by 50-100% (according to my test cases) and removes the inspector warnings mentioned above :)

    Thanks to Mike for spotting that the current bottleneck of the toolkit was how it instantiated the game objects, not the actual shattering code!
     
    Last edited: Dec 30, 2012
  49. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I just wanted to let you know that I've fixed the bug in the Buoyancy Toolkit (upcoming release 1.4) and the 2 toolkits should now work perfectly together :)
     
  50. Shaka

    Shaka

    Joined:
    Apr 24, 2010
    Posts:
    51
    Hi (Hej) Gustav!

    I'm playing around with your awesome toolkit and I have a question.
    I'm using the 2D toolkit for my game and it has 2D-sprites consisting of simple rectangular planes (two tris) and I can't seem to get shattering to work on them. I've unchecked the "FillCut" checkbox but that didn't have any effect. I looked around in the code and it seems the Hull.IsEmpty-property is always set to true for the mesh (edge count < 6).
    Is this a bug or is the shatter toolkit not designed to work with meshes of this low resolution?

    Regards/Per