Search Unity

[RELEASED] 2D ColliderGen - Generate Precise Polygon Colliders For Your 2D Sprites

Discussion in 'Assets and Asset Store' started by Pixelcloud-Games, Mar 14, 2013.

  1. KeepTrying

    KeepTrying

    Joined:
    Feb 23, 2011
    Posts:
    119
    @Pixelcloud Games Anyone knows if 2D ColliderGen is able to generate a 2D Collider from one 3D Mesh,
    i need to convert a 3D Maze in .obj format, into Polygon 2D Collider.
    Thank you.
     
  2. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi

    Sorry, additional 2D Toolkit functionality (that is not already supported) will not be supported in the near future.

    Kind regards,
    Harald
     
  3. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    That's a rather funny workflow you have there ;)
    If you can render your obj file to an image (you can write a blender script for that), then set the transparent parts in the image via photoshop or gimp or whatever and can then use 2D ColliderGen to create your PolygonCollider2D.

    Kind regards,
    Harald
     
  4. KeepTrying

    KeepTrying

    Joined:
    Feb 23, 2011
    Posts:
    119
    @Pixelcloud Games The old version of my game was using "Unity 3D Colliders" now i'm running with "Unity 2D Colliders" to make the game more lightweight.

    "If you can render your obj file to an image" i've tried this with a lot of "2D Collider Generators" and got some crazy weird results like jagged edges, no straight collider lines and so on.

    I'm getting 2D ColiderGen right now, let's see what i can do with this tool ._.
    Thank you Mr. Cloud.
     
  5. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    If the transparency is set up in the image, it should work I guess. If you have any problems, let me know! If I should miss a forum post and not respond for days, just drop me an email.

    Cheers,
    Harald
     
  6. KeepTrying

    KeepTrying

    Joined:
    Feb 23, 2011
    Posts:
    119
  7. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    105
    Hi! i boguth your asset, but i dont get the add component dialog, can you please help me here? tried re importing collidergen, but i did not worked im using 5.2.0f3 win 7 64 bits



    also, i have another question, is it possible to copy the collider i generated with a object with a sprite renderer to an object without a sprite renderer? i like to keep the physics collider wich is not kinematic seperate from the hitbox collider wich is kinematic.
     
  8. Chaosgod_Esper

    Chaosgod_Esper

    Joined:
    Oct 25, 2012
    Posts:
    295
    is there any way to get a collider been created at runtime?

    cause i'm creating a tilemap editor for my game, and i'm looking for a way to create a collider put of a runtime created collision-Texture.

    The collider doesn't need to change by every tile drawn..
    instead we want to add a button (like in unityEditor), that calculates the collider once per click at runtime.. so we make big changes, click button.

    And later, of course, create the collider once the level is loaded..
     
    Last edited: Nov 30, 2015
  9. Silverlode

    Silverlode

    Joined:
    Apr 9, 2013
    Posts:
    40
    I am receiving an error when building for iOS. I am using code to generator colliders at runtime.

    IL2CPP error for type 'ConfusedByAttribute' in assembly 'D:\Users\mark\Documents\GitHub\Proj\Temp\StagingArea\Data\Managed\2DColliderGen_Runtime.dll'​

    The error says I will get more information doing a development build, but actually no more information is provide. This link suggests its due to an absence of a .mdb file.

    Other errors occuring at the same time make me wonder if the DLL code still has some references to the editor enivronment that should be otherwised defined

    Failed running C:\Program Files\Unity\Editor\Data\il2cpp/build/il2cpp.exe --copy-level=None --emit-null-checks --enable-array-bounds-check --enable-symbol-loading --development-mode --extra-types.file="C:\Program Files\Unity\Editor\Data\il2cpp\il2cpp_default_extra_types.txt"​

    What should I do to try to fix this?
     
  10. Silverlode

    Silverlode

    Joined:
    Apr 9, 2013
    Posts:
    40
    Sorry, false alarm. I updated to 2.6 and this issue has been resolved. Thanks for fixing it already! :)
     
  11. ecosky

    ecosky

    Joined:
    Sep 9, 2013
    Posts:
    3
    Great plugin!

    I have a few suggestions:
    1) Have an option to detect & generate Box or Circle Collider 2D if the points happen to be rectangular or circular within tunable tolerances. This would be helpful for improving performance for tile maps with lots of square sprites.
    2) Have an option to generate an Edge Collider 2D instead of Polygon Collider 2D.
    3) Add a point snap value, causing vertex coordinates to be snapped to multiples of that value.
    4) Add a merge distance, causing any vertices within this distance of each other to be moved to the center of the group.

    Thanks for the time saving tool!
     
    Last edited: Jan 3, 2016
  12. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi!

    Sorry for the late fix, it was more work than I expected it to be - on the other hand I improved some more things along the way. A new package with your bugfix of the 'Component' window entry not showing up is now on the asset store, please just get the update.

    It should work if you only copy the Collider component via the inspector context-menu and "paste component as new" to the desired object. Or is that not an option?

    Kind regards and a happy new year!
    Harald
     
  13. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    That should already work with the provided RuntimeAlphaMeshCollider.cs script - however you will need to write some code to fill a binary image (0 and 1 for empty and full pixels) or a texture which you then update at runtime.
    The latest update day ago should provide a much improved and more comfortable version of the RuntimeAlphaMeshCollider script.
    Hope that helps!

    Kind regards and all the best for 2016!
    Harald
     
  14. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    You're most welcome! :)
    Kind regards and a happy 2016!
    Harald
     
  15. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi!
    Thanks very much for your words and your ideas!
    Detecting circles and boxes seems like a nice idea. I will have to think that through a bit on how to most easily detect this - one box or circle is easy, but fitting multiple and deciding when to use circles/boxes and when polygons seems rather non-trivial to me at first thought..

    Thats a very good point, I will definitly implement this in the next release.

    Nice ideas as well! I will try to fit these into the next release.

    Kind regards,
    Harald
     
  16. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    One more question: what is your usecase of the point snap feature? Would you prefer pixel-based values (multiples of 10px) or ratio-based values (10-th of your image)? Nevertheless, I could implement both, but I'm just curious. :)

    Kind regards and a happy new year! (forgot that in the last posting :) )
    Harald
     
  17. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    2D ColliderGen v2.7 has been released on the Asset Store!

    update_2.7_website_news_small.png

    New Features:
    - Made RuntimeAlphaMeshCollider script more powerful.
    - Added preference value "Collider is Trigger" to
    automatically set generated colliders to be triggers.

    Bugfixes:
    - Fixed 'Component' menu not showing up in latest Unity
    versions.
    - Fixed problems with Undo system.

    Hope you like it! :)
    Wish you all a Happy New Year 2016!
    Cheers, Harald
     
  18. TheOz

    TheOz

    Joined:
    May 21, 2011
    Posts:
    32
    Hello Pixelcloud

    Im getting the following error when importing 2.7:

    Assets/2DColliderGen/Editor/GenerateColliderTK2DHelper.cs(528,73): error CS0117: `Activator' does not contain a definition for `CreateInstance'

    Any help would be great.

    Anorak
     
  19. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hello Anorak

    I guess that another package has a class named Activator that causes a name clash.
    Please try the following:
    a) Replace line 528 in GenerateColliderTK2DHelper.cs as follows:
    colliderIslandsArray[index] = System.Activator.CreateInstance(colliderIslandType);
    b) If this does not work, replace it with the following line:
    colliderIslandsArray[index] = new tk2dSpriteColliderIsland(); // Activator.CreateInstance(colliderIslandType);

    Please let me know which one solved your problem, thanks!
    Cheers and HTH,
    Harald
     
  20. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    43
    Hi,

    I face some problems with RuntimeAlphaMeshCollider.
    It seems like a memory leak or endless loop, I try to generate colliders from a realtime camera kinect depth mask.
    Another issue is that when no islands are found so working on a texture with no opaque pixels you stop when in editor mode, if I fix this then you get a nullptr exception, I fixed that too. But the freeze issue stays, without your part my program just runs fine.
    best,
    Robert
     
  21. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi Robert,

    I just fixed your issue, please check the PM I just sent you for your download link.

    Apart from the bugfix the RuntimeAlphaMeshCollider script now uses a second processing thread for improved performance.
    This all will later be included in the following official release.

    Please let me know if this worked for you.

    Kind regards,
    Harald
     
  22. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    2D ColliderGen v2.8 has been released on the Asset Store!

    update_2.8_website_news_small.png

    New Features:
    - Added support for EdgeCollider2D.

    screen2_unity43_small.png

    - RuntimeAlphaMeshCollider now uses a separate processing
    thread for improved performance.

    MultiThreadedRuntimeColliderGeneration.gif

    - RuntimeAlphaMeshCollider now supports calculating
    colliders of individual sprite frames or other sprite
    atlas elements on the fly.
    Previously only preprocessed sprites were possible.

    Hope you like it! :)
    Cheers, Harald
     
    Last edited: Jun 3, 2016
    Arkade likes this.
  23. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Just fixed a compile-error that occurred during non-editor builds (a #if UNITY_EDITOR guard was missing). Just submitted an update to the Asset Store, should be through in a few days. If you need the fix earlier, you can download this file and copy it over the one in the 2DColliderGen/Scripts directory:

    http://pixelcloudgames.com/wp-content/uploads/2016/06/UnityBuiltInSpriteTools.cs

    Kind regards and sorry for letting this one slip through,
    Harald
     
  24. xiaoke36

    xiaoke36

    Joined:
    May 19, 2015
    Posts:
    3
    Hi Pixelcloud,

    I have a problem when generating polygon collider 2d with a alpha8 Texture at runtime . I use the RuntimeAlphaMeshCollider script because the map could be changed during playing.

    It works when I set the MaxPointCountPerIsland a small number.But when I set a bigger number,some colliders disappeared. How can I get a accurate collider at runtime?Thanks a lot!
    Untitled2.gif
     
    Last edited: Jun 20, 2016
  25. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi!

    Thanks for pointing this out, I'll get back to you with a fix soon!
    Kind regards,
    Harald
     
  26. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    I've fixed the issue, please download the hotfix package here and copy the dll over the original one in 2DColliderGen/Plugins/2DColliderGen:

    pixelcloudgames.com/wp-content/uploads/2016/06/2DColliderGen_Runtime_2.9.0.zip

    I'll submit an official package update to the asset store very soon.

    Kind regards,
    Harald
     
  27. xiaoke36

    xiaoke36

    Joined:
    May 19, 2015
    Posts:
    3
    Problem solved.Cool! Thank you Harald!
     
  28. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    You're welcome! :)
    Just submitted the package update to the Asset Store for review. Shall be live in a couple of days.
    Kind Regards,
    Harald
     
  29. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    FYI: It's officially released on the Asset Store now.

    Cheers,
    Harald
     
  30. Oruji

    Oruji

    Joined:
    Nov 5, 2012
    Posts:
    13
    [EDIT]
    The solution was to check "Convex" in the MeshCollider component.
    Checking "Force Convex" in the AlphaMeshCollider component did not help.

    Hi,
    I just bought the package and I'm optimistic, but I'm having a problem with the mesh generation.
    I want to generate a mesh collider from a sprite.
    It generates a mesh, but it's is only wrapping the sprite's edges, it does not generate a mesh for the face of the sprite.

    Which means I can raycast the sides with success, but I cannot raycast the face of the sprite, which is what I want.
    How do I fix this?

    Thanks,

    upload_2016-8-2_8-1-45.png
     
    Last edited: Aug 2, 2016
  31. McSpiffy

    McSpiffy

    Joined:
    Aug 14, 2013
    Posts:
    11
    Hi I have been using 2D ColliderGen for a while now and I'm loving it! Atm I am using the newest version of the RuntimeAlphaMeshCollider script and I have a question. Is there a way to have the script tell me when a piece of the image has separated from the rest of the image? You see I am developing a space-ish game where you can shoot into images and separate them in half and in doing so I remove the separated pixels from the original image and create a new gameobject with the the pixels that were separated as the new image. I have all this in place but My scripting skills aren't the greatest so my way of detecting when the image separates is a little messy and can be buggy at times. As I use you're script already I figured that it may be doing this procedure as well just a lot more efficient then the way i'm doing it. So back to my question Is there any way for me to hook into you're script for it to tell me when a section of the image has been separated from the rest?
     
  32. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi!
    Just returned from 2-week Holidays, thus the late reply.
    Great to hear that you like it, thanks for purchasing it!

    You could store the last number of separate island regions and see if the number has increased or not (an island region can be seen as a separate part in you setup).

    Code can be adapted from the following sections, RuntimeAlphaMeshCollider.cs, around line 375f.
    Code (CSharp):
    1.  
    2. bool anyIslandsFound = CalculateIslandStartingPoints(m_BinaryImage, m_BinaryImageWidth, m_BinaryImageHeight, ref m_ClassificationImage, ref m_Islands, ref m_SeaRegions);
    3. // [..]
    4. int newNumIslands = m_Islands.Count;
    5. if (newNumIslands > m_LastNumIslands) {
    6.     wasSplit = true;
    7. }
    8. m_LastNumIslands = newNumIslands;
    9.  
    Hope this helps!
    Kind regards,
    Harald
     
  33. McSpiffy

    McSpiffy

    Joined:
    Aug 14, 2013
    Posts:
    11
    Hey thanks for the reply. It would seem while you were away I came up with a similar solution. Its good to know I was on the right track.
    Code (CSharp):
    1. if(m_Islands != null && currentIslandCount != m_Islands.Count)
    2.         {
    3.             oldIslandCount = currentIslandCount;
    4.             currentIslandCount = m_Islands.Count;
    5.         }
    6.         if(currentIslandCount != oldIslandCount)
    7.         {
    8.             // need to send a call!
    9.             if(splitTexScript == null)
    10.             {
    11.                 splitTexScript = GetComponent<TextureSeparation>();
    12.             }
    13.             splitTexScript.CheckForSeparationTwo();
    14.             oldIslandCount = currentIslandCount;
    15.         }
     
  34. Mr_Mendel

    Mr_Mendel

    Joined:
    Dec 31, 2013
    Posts:
    16
    Hi,

    I gon't know if I am being dumb, but can I select say two sprites and get it to make a plygon collider that goes over both at once?

    Thx
     
  35. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi,

    That will not work unfortunately - you need to combine the two sprites in an image editing program of your choice and then create the collider using this combined image.

    Kind regards,
    Harald
     
  36. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    @Pixelcloud-Games Hi,

    I'm using updated version from AssetStore (2.11.0) and Unity 2017.1.f03. When I add the component AlphaMeshCollider, it freezes the editor, but doesn't crash. If i leave it there, after sometime, there is an "out of memory" message on console. Also the editor (frozen) consumes over 4GB of ram

     
  37. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi @sevensails,

    Oh, thanks for the report, I will check this and get back to you with a solution ASAP!
    Kind regards,
    Harald
     
  38. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi again,

    Unfortunately I was not able to reproduce your problem - when I e.g. select a GameObject with a Unity SpriteRenderer component and choose "Add AlphaMeshCollider" everything is added as expected.
    (Tested with your listed Unity version Unity 2017.1.f03).
    Could you please zip a minimalistic project that reproduces your problem? That would help a lot with resolving your problem.

    Kind regards,
    Harald

     
  39. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Hi @Pixelcloud-Games ,

    Surprisingly I tested again and it worked. Really strange, because I tested several times, and the freezing was really happening.

    Anyway, probably a machine restart "fixed" this :)
     
  40. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Thanks very much for the update, glad it fixed itself :).

    Kind regards,
    Harald
     
  41. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi everyone,

    I just noticed that RawImages on Canvas objects were not working, but only Sprites were - I have just submitted an to the AssetStore, just waiting for approval.
    If anyone needs this feature earlier, please drop me a message!

    I minor change to get rid of menu-related 2 errors that pop up once:
    Preferences window and 2D ColliderGen TK2D window are no longer part of the 'Component' menu but listed under 'Window - 2D ColliderGen' now.

    Everything is tested under 2018.2 now.

    Cheers,
    Harald
     
  42. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    The new version 2.12 was just accepted by the AssetStore. So get the update if you need support for RawImages on Canvas objects :)! Link: [http://u3d.as/4iB]


    Cheers,
    Harald
     
    xiaoke36 and vicenterusso like this.
  43. ddubord

    ddubord

    Joined:
    Jul 8, 2012
    Posts:
    3
    Does Unity's CompositeCollider2D work with 2D ColliderGen created PolygonCollider2D?
     
  44. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Thanks for your interest in 2D ColliderGen!
    I will have a look if this works. I think it does, but need to check to be sure.
     
  45. ddubord

    ddubord

    Joined:
    Jul 8, 2012
    Posts:
    3
    Cool, thanks for checking!
     
  46. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Yes - It works as expected. You can change the vertex count, etc via the AlphaMeshCollider interface, and the CompositeCollider2D will update its content correctly:

    upload_2018-12-6_9-11-11.png

    upload_2018-12-6_9-12-46.png

    So there should be no problems running 2D ColliderGen with CompositeColliders.
     

    Attached Files:

  47. ddubord

    ddubord

    Joined:
    Jul 8, 2012
    Posts:
    3
    Awesome! This is a life saver for me. Thanks for looking into it for me and expect a purchase soon.
     
  48. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    You're most welcome! Thanks for your interest in 2D ColliderGen! If you should run into any problems, let me know!
     
  49. MercurialKid

    MercurialKid

    Joined:
    Aug 30, 2018
    Posts:
    21
    Hi PixelCloudGames. I may have just bought in error. My problem is that I'm using a light asset with a tilemap. My tilemaps are unusual, and I'm having to manually add box colliders to each platform. I was hoping to use this asset to generate polygons for my tilemap objects. Is there any way to accomplish this? Otherwise, this asset may not be much use to me, I'm afraid.
     
  50. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi,
    Can you send me a minimal project that shows your problems? Then I can see what I can do to help.
    Kind regards,
    Harald