Search Unity

2D Toolkit - 2D in Unity made simple [RELEASED]

Discussion in 'Assets and Asset Store' started by unikronsoftware, Jun 16, 2011.

  1. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Don't you just want to create your sprites so the anchor/origin is at the bottom center? That way flipping won't move the sprite itself.

    You can do the same with regular cameras, though its a tiny bit of code to rescale for different resolutions. You can't do funky stuff like nonuniform scale to fit screen though.
     
  2. Code_Helix

    Code_Helix

    Joined:
    Feb 21, 2012
    Posts:
    79
    Ah! Thanks! I'll check it out to see if that fixes that problem so I won't have to use different animations. I really appreciate your help and sorry for all the constant questions lol. Still new and trying to figure out how this works and hope I'm not being too annoying lol. Again thanks for help pointing me in the right direction.
     
  3. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hi there,
    I've just started using tk2dTextMesh and I'm having a little trouble getting it to update in the game.
    I am using this function in my project -

    Code (csharp):
    1. function UpdateName(UpdatedName : String){
    2.     PlayerName2dTkText.text = UpdatedName;
    3.     ReScaleName();
    4. }
    When I run this function it doesn't update the font in the viewport (and in the game) but if I highlight the text mesh in the hierarchy and look at the component, it seems that the text has been updated.
    Is there something I'm missing out on to get the text to update here?

    Thanks
    Pete
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @petey - you need to call Commit() after changing any text properties.
     
  5. mboog12

    mboog12

    Joined:
    Oct 4, 2011
    Posts:
    91
    Hello, I have recently updated to the newest version of tk2d. There is one new feature that is bugging me :
    in the inspector there is a new button with suspension point, which acts as a browse button for sprites. the problem is that I found the old button much more useful for me (the one that let you open the collection for the sprite). In early development I need to change the colliders a lot, I also need to check the spriteids fairly often. Now, if I want to open the collection for a certain sprite in the scene I need to type in the collection name in Project tab, and that takes more time than simply clicking the button in the inspector.
    Just my .02$ :)
     
  6. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That option is still there, it is just hidden by default now. Go into "2D Toolkit > Options" and turn on "Display Edit Button". You should now have the button back where it was.

    For what its worth, I've changed it in 1.92 - I reduced the size of the button (represented by "e"), and its on by default.
     
  7. JOHNMCLAY

    JOHNMCLAY

    Joined:
    May 23, 2012
    Posts:
    38
    Hi there Unikron,

    First off, kudos for creating such a helpful extension for Unity, you've made a lot of people very happy! :D

    Also, a question, do the animated sprites support animation events in Unity...akin to how regular 3D animations are supported (e.g. a walk-cycle using animation events to determine when a footstep sound is played)?
     
  8. kremedved

    kremedved

    Joined:
    Nov 8, 2012
    Posts:
    14
    Have a problem: there is an object "raft" with z-coordinate = 28 and water (duplicated animation by X-axis) with z = 24.8. If I use the camera tk2d, all looks great!

    $raft_1.png

    But when I switch to a standard camera Unity, some water animations draws on background of the raft.

    $raft_2.png

    Background: CutOutVertexColor
    Raft: BlendVertexColor
    Water: BlendVertexColor
    UnityCamera:
    $UnityCamera.png
    tk2dCameraSettings:
    $tk2dCamera.png

    How to make with a "UnityCamera" to water draws in the foreground, while the raft in the background(as with tk2dCamera)?
     
    Last edited: Mar 10, 2013
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The "normal" camera is perspective. Write a script to set
    camera.transparencySortMode = TransparencySortMode.Orthographic;
    and it will sort correctly.
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @JOHNMCLAY

    Glad you like 2D Toolkit.

    The animated sprites don't support animation events like in the Unity system, but they do support "triggers". You can set up triggers in the animation editor, and these will call the animationEventDelegate. You can most certainly use this to trigger footstep sounds, etc.

    Refer to sample scene #5, and check out tk2dDemoAnimController.cs to see how you wire this up to your code.
     
  11. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  12. kremedved

    kremedved

    Joined:
    Nov 8, 2012
    Posts:
    14
    But i need change z-coord UnityCamera to zoom in/out...
     
  13. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  14. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hey thanks for the quick reply!
    I'm just wondering what would be the best approach for me though. I'm trying to make chunks of text fade on and off at different points throughout the game. According to the docs though, it would be bad to call commit too often but surely you'd have to if you were fading it out.
    Could you advice me of the best way to go about this?

    Thanks,
    Pete
     
  15. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The cost of calling Commit depends entirely on the number of characters. If you solely change colors and call Commit, the cost is a lot less than changing text + colors. Depending on how much text you have (and how many characters in MaxChars), just changing colors + Commit might just work well enough without having to resort to any other options.

    Another option, of course, is to use a custom material when you need to fade some text, and then change the color property on the material. That may add a draw call to the text while fading, but that might be better than the overhead above.

    Its hard to definitely recommend one over the other - it depends entirely on your game. I suggest trying option #1 first, and see how it goes.

    p.s. 1.92 beta 1 improves color update performance significantly. Try that first if option one is just a touch too slow.
     
  16. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    I'm looking for a 2D solution that I can add colliders on certain animation frames and not on the others eg for a beat em up where i'd want a collider on the fist for a few frames, can 2D Toolkit do this?
     
  17. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You set up colliders on sprite frames rather than the animation as a whole, so you should be able to do this. However, you are limited to animating axis aligned box colliders at the moment - this might not be sufficient for you if you're planning on making a beat em up. It really depends on what your

    Arbitrary collider set up is definitely coming in a future update, but if you need it right away, you'll have to code it in yourself. Drop me an email at support at unikronsoftware.com if you need any further details on this.
     
  18. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Thanks again, I'll give it a try.
     
  19. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    Thanks for the reply. Sounds like it would work. Can I set up more than 1 collider per frame?
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No you can't at the moment. That and arbitrarily rotated colliders will be coming in the collider system update. You can have polygon (mesh) colliders, but you can't animate that due to performance constraints.
     
  21. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    OK thanks, whats the ETA of the collider system update please?
     
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I'd rather not discuss that publicly in case I don't meet it :)
    Drop me an email (support at unikronsoftware dot com) and I'll share a bit more detail on the current roadmap for the software.
     
  23. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  24. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    160
    2D ColliderGen extension for the 2D Toolkit framework has just been released
    - Create Precise Polygon Colliders for Entire Scenes at the Click of a Button - Instant 2D Physics -

    First of all, thank you for creating 2D Toolkit! It's a great framework, and so many people already benefit enormously from it!

    Please allow me to inform you that we have just released the extension 2D ColliderGen which fully integrates with 2D Toolkit.
    The 2D ColliderGen framework allows you to automatically generate precise polygon colliders for multiple sprites from the sprite image’s alpha-channel. It fully integrates with the 2D Toolkit SpriteCollection editor and lets you tweak the collider outline afterwards as usual, but it replaces the tedious work to manually set each single vertex by handfor each sprite (and it's fun to use ;) ).

    Visit the
    Unity Forum Thread here for more information.

    View attachment 46863

    $screen2_parameters_mirrored.jpg

    View attachment 46865

    Tutorial Video


    We have chosen to officially support 2D Toolkit because we think it's one of the three best 2D extensions for Unity and we use it ourselves, but that it could get even better with automatic MeshColliders for 2D sprites.

    Hope you like it! :)
    If you have any questions, don't hesitate to ask!
    Thank you!
     
  25. DanarKayfi

    DanarKayfi

    Joined:
    Aug 27, 2012
    Posts:
    72
    Hi im getting this error on 1.91final with Unity 4.1
    when Rebuilding Index

    MissingReferenceException: The object of type 'tk2dIndex' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    tk2dEditorUtility.CreateIndex () (at Assets/TK2DROOT/tk2d/Editor/tk2dEditorUtility.cs:215)
    tk2dEditorUtility.RebuildIndex () (at Assets/TK2DROOT/tk2d/Editor/tk2dEditorUtility.cs:60)

    What should i do!!
     
    Last edited: Mar 16, 2013
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Get 1.91 + patch 1 from here which fixes the issue:
    http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1313.0.html

    The same update has been submitted to the asset store, but it hasn't been approved yet.
     
  27. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hi there,

    Hey I've been looking at my 2d toolkit font situation and I think I'm going to revert back to the standard text meshes for the time being, it just seems that I have a lot of text elements that fade on and off so it will probably be a lot of work for me and eventually have more of a hit to the games performance.

    Just wondering though, would you consider implementing a more lightweight color setting (similar to the one in 2dtk sprites) for fonts? I imagine im not the only one out there who has fading text elements.

    Anyway, just a thought. I'm loving this extension by the way it's a massive time saver!

    Thanks,
    Pete
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi Pete,

    The reason the text mesh color change is slower than the sprite color change is that while both use vertex colors, the text mesh obviously has a lot more vertices due to the number of characters in there. So think of it as changing N sprites at a time, N being the maxchars in your textmesh.

    You can do different specific things based on your needs, but ultimately it boils down to two main choices - break batching and use materials - not updating geometry, or update geometry as its being done now. There's not much else that can be done in a generic toolkit without very specific optimizations.

    p.s. Did you try 1.92 beta? The reduced bandwidth should have made things quite a bit faster updating geometry.
     
  29. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hey thanks for the update,
    I'm a little scared of using beta's at the moment but I might have to give it a try.
    I guess one of the things that I am stumbling on is that I'm using HoTween to animate the opacity of (as well as a bunch of other parameters). So the only way I can think of getting it to work (without breaking batching) is to run commit a bunch of times while the text is fading (from the HoTween). Does that sound right? I might give it another go with the beta and see how it goes.
     
  30. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yup, calling Commit every frame is the only way to do it, but only when the color/opacity has actually changed.
     
  31. KoboldgamesUser

    KoboldgamesUser

    Joined:
    Nov 20, 2010
    Posts:
    11
    I just updated to Unity 4.1 and downloaded the latest version of the 2dtk from the asset store. I keep getting this error when commiting large collections to multiple atlasses.

    Is there any solution for this one? Any hints what I'm doing wrong?

    MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEngine.Texture.get_height () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/Graphics.cs:683)
    tk2dSpriteCollectionBuilder.Rebuild (.tk2dSpriteCollection gen) (at Assets/TK2DROOT/tk2d/Editor/Sprites/tk2dSpriteCollectionBuilder.cs:923)
    tk2dSpriteCollectionEditorPopup.Commit () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:437)
    tk2dSpriteCollectionEditorPopup.DrawToolbar () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:427)
    tk2dSpriteCollectionEditorPopup.OnGUI () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:826)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
     
    Last edited: Mar 20, 2013
  32. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
  33. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This might be a bug. I'll look into it.
    Does it work properly when not using multiple atlases?
     
  34. x8105

    x8105

    Joined:
    Apr 4, 2011
    Posts:
    5
    We have a scene with 10,000 box colliders 2,000-3,000 batched at any given time, targeting next smart phone and tablet devices. Previous to using 2dtk we used a 16x16 polygon plane, subdivided and uvmapped with our artwork, In script we changed the global property of the material in a 5 min ping pong between 2 colors to simulate lighting. Well our global material script does not work with the current 2D toolkit, because each sprite can have it's color changed individually, my coder could rip it apart and figure it out in a few min, but it's his birthday and I am trying to give him less work to do by researching a path to resolve this. Would calling commit every frame be the direction to go, and also what kind of performance hit does calling commit have on a scene of 300-400 sprites batched in upwards of the 2000-3000 range.

    Oh and is there any reference on stitching repeated sprites or optimizing 2d toolkit polygons and colliders at run time similar to the custom dicing that 2d toolkit does in the sprite editor?

    x8105 of ZombieChickenTaco
     
  35. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That would be a bad thing to do.
    It is much more efficient to change the shader and do it that way, especially since you want all of them to change in the same way (i.e. simulating lighting). It is just 2-3 lines in there.

    There is some code impelemtned in the static sprite batcher which merges polygons for the collider. Is that the kind of thing you're looking for?
     
  36. x8105

    x8105

    Joined:
    Apr 4, 2011
    Posts:
    5
    Ah very good on the material lighting, now for polygon mergers, our scene and fps are fairly steady at 8000-10000 blocks on my Galaxy S3 45-50fps, and we are looking at ways of enabling and disabling blocks to get the levels out of the 128x128x3 sprite range and i into a 128x1024x5, my artistic brain can wrap around the concept of it, code? Well I'm better at eating glue. If I could get a referance to the mesh combiner name I can do an Alt+f for... to pass onto the BRAIN behind this all working...
    With our voxel system handling... well everything now, it's a matter of reducing the total visible voxel/sprite prefabs in the level, by using the fog of war approach, but with a dynamic polygon based on area size with tiled sprites masking the hidden treasure, fog of war combination. oh and keep up with the insane amount of distance the camera repeatedly covers in short periods of time to the ever changing landscape all within the bounds of current gen mobile and tablet... AND I CAN'T KEEP UP WITH MY CODER... I am just a poor little artsy guy. !!! speaking of which.... I dumped my 20 scattered sprite sheets I spent HOURS... DAYS to optimize... only to exported them all as single sprites because your atlas compiler is G TO THE F N D AWESOME!.. Dicing rules the texture size reduction gods...... then you have to pull the 2D Tool kit UI thing on me, as I get comfortable with using NGUI to handle the user interface........

    Would you know of any GOOD practical way of using a sprite in NGUI AND with 2D tool kit, where the Sprite can be within the game play and the GUI without redundant atlas real-estate usage while maintaining draw calls at a 1 to 2 count ... we are currently at 13 drawcalls.. seams kinda high atm. ?

    x8105 of ZombieChickenTaco
     
  37. KoboldgamesUser

    KoboldgamesUser

    Joined:
    Nov 20, 2010
    Posts:
    11
    If I uncheck the multiple atlas option I get the correct warning that there are to many sprites to fit in one atlas. When using less sprites it works properly with one single atlas. I attached an image of the collection settings where the exception is thrown.
    $Dwm 2013-03-22 10-12-15-86.png
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I've not been able to reproduce this in Unity 4.1.1f4. Is that the version you've tried it on?
    In any case, if its still an issue in that version, email me at support at unikronsoftware.com and we'll investigate this further.
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I'm afraid there isn't a good way to share sprites between NGUI tk2d. The atlas formats aren't compatible.
     
  40. x8105

    x8105

    Joined:
    Apr 4, 2011
    Posts:
    5
    and this is where my creative brain out thinks yours MWAHAHA, .. correct in both NGUI and the epic ever so awesome 2DToolKit.. The Atlases are both very different... Except for 2 things. Texture, and Material. Granted each of the Atlas' have different shaders, I noticed that both have a cool feature that can cause for some frustration and redundancy if not implemented at the correct moment in the development pipeline.. the very last! thing before build. So In the project build, Ngui has Reference Atlas, and 2D toolkit has .... Multiple materials. issue would be change something on one of the atlases you would be ever so lucky to resetup all that you worked for... bleh. I suggest a LOCK ATLAS ... unless over looked it. COME ON WINDOWS UPDATE YOU MAKN ME MAD, 4 hous post pone is NOT 20 min! well better get this reboot out of the way......


    Ans so it was told that x8105 was never to be heard from again. TheEnd.

    GOT DANdruft1111!!!!!
     
  41. Code_Helix

    Code_Helix

    Joined:
    Feb 21, 2012
    Posts:
    79
    I am having some trouble creating a character controller for my player as can't seem to figure out how to do the jump as am using the Unity physics. So I was wondering if anyone knows of a good platformer script that works with the 2D Toolkit with basic moving and jumping to help give me some where to start as I am still new to scripting. I appreciate any help you all can give me.

    Edit: I found this link which is tutorial from the Walker Boys in creating a Mario clone so I was wondering if it will be difficult to convert it to C# and using 2D Toolkit to handle all the sprites.
     
    Last edited: Mar 23, 2013
  42. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I've not watched that tutorial, but the character controller should work fine with our without any graphics component applied to it. As such, it should work just fine. What exactly happens when you try to do it? Depending on how big you set up your sprites, and whether you set up to use tk2dCamera or not, default gravity might be too high / low.
     
  43. maaboo

    maaboo

    Joined:
    Dec 26, 2012
    Posts:
    12
    I didn't test it, but i'm planning to use 2D Platform Controller (JNA Mobile). It has any movements (walking, jumping, climbing, even wall jumping).
     
  44. Code_Helix

    Code_Helix

    Joined:
    Feb 21, 2012
    Posts:
    79
    When using a rigid body the player will slowly fall right through the ground and I'm not so sure why that is. Also when I tried with a regu;ar camera the player will float above the ground and it won't allow me to place it correctly for some reason.
     
  45. Code_Helix

    Code_Helix

    Joined:
    Feb 21, 2012
    Posts:
    79
    Can you let me know how well it works as I can't purchase it at the moment.
     
  46. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    With the regular ortho camera the issue is the size is too small, i.e. the default separation makes it think its colliding with the body when it isnt. You can either try a bigger ortho size, or change the min penetration for penalty in Edit > Project Settings > Physics.

    With tk2dCamera, gravity is probably too low for the scale.
    If you're making a platformer with a large scale, use an ortho camera - say set it to an ortho size of 10 to start with. Its pretty arbitrary, but 10 should give you half decent sizes with default Unity physics. 10 = 20 meters from top of screen to bottom. as you can imagine what you're drawing in your sprites makes a difference to what you set this to.

    Getting gravity / penetration sorted is really important - you will run into issues with any other package that uses Unity physics until you get scales sorted out properly.

    A good way to work this out is to add a rigid body to a box / sprite with a box collider, and make it fall the way you expect it to. Once you get this workign properly, the character controller will behave half decently too. Once you get that working perfectly, using any other package will work properly too.
     
    Last edited: Mar 24, 2013
  47. Alucard384

    Alucard384

    Joined:
    Nov 21, 2010
    Posts:
    8
    I've been having what seems like similar issues to the original poster. The animations for a boss in my game have around 90 frames for each animation. I updated Unity to one of the newer versions when it popped up a few days ago and 2DToolkit to the latest beta release when I was having problems and I have not been able to create a collection that goes over 1 atlas even if multiple atlases is checked. Is this a bug?
     
  48. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Can you email me at support at unikronsoftware dot com, please? This looks like its a bug in that version of Unity, but I'd like to check some stuff with you before firing off a bug report.

    Edit: If its definitely a bug, I think it might be possible to work around it.
     
    Last edited: Mar 25, 2013
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  50. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    241
    Hi Unikron, awesome news about the 2D UI kit. It couldn't come at a better time either - I was just about to shell out for NGUI.

    Any sort of ETA for the final release?

    I'm a bit hesitant to start building something with the beta in case you lose backwards compatibility in the final release. For this reason I also haven't even opened the package, so this might be a redundant question but will you have some sort of tutorial / vids made up for training?