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
    This is likely because the texture is set up with bilinear / trilinear filtering instead of point filtering. Setting it to point filtering will produce better results, and #2 you could add padding in texturepacker to make it upscale better.
     
  2. JustDave1961

    JustDave1961

    Joined:
    Jan 5, 2013
    Posts:
    14
    Thank you for the fast reply!

    It WAS the texture filtering! I can't thank you enough! I would have never have found this on my own!
    Also, thanks for a great product!

    Dave
     
  3. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    Hey.

    Is there any way to improve how the plugin builds atlases. Currently I'm getting atlases produced that are wasting 40-60% of the texture space which is not acceptable especially in a mobile game.

    Thanks.
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The atlas packing should be really pretty tight. You shouldn't waste > 50% unless you're mixing some pretty weird shapes that cause it not to be able to go down one atlas size. Most of the time, you can add more sprites to the collection to fit more stuff in, but sometimes you will have to sacrifice space for atlas sharing to reduce draw calls.

    Its impossible to make any concrete recommendations without looking at the atlas though.

    Edit: If you have long thin shapes in the atlas mixed with regular square-ish ones that could cause issues. You could work around that by using dicing the long thin sprite.
     
  5. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    Yea it was really weird. One was wasting 66% with mostly uniform shapes. After breaking a few things up a little more though it's down to 38%. There's probably a few more things that can bring it lower so i'll keep trying. Thanks for the quick response.
     
  6. GREBENOTS

    GREBENOTS

    Joined:
    Jan 24, 2013
    Posts:
    44
    EDIT: Solution below:

    Has anyone had any issues of large images being unable to downscale? For instance:

    A 2048x1536 background image (sprite) with a resolution over-riden tk2d camera will look perfect on the ipad, but when I test on an iphone, everything runs, but the sprite just shows as a big black background, almost like the sprite container is rendering, but the actual sprite isn't.

    I have no issues of smaller images upscaling to ipad size. Just vice versa.

    Does that make sense? Also, this issue is only happening on actual device testing. Testing in the simulator(built with simulator SDK) works as expected (and flawlessly I might add). I'm a bit puzzled.

    Solution:
    Apparently the iPhone4 has a maximum Atlas size of 2048 (probably has already been stated in this thread). To fix my problem, I changed my filtering to point method, changed the padding to 0, which allowed me to reduce the Atlas size from >4000 to 2048, and viola, everything works as intended.
     
    Last edited: Apr 17, 2013
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    About the max texture size on iOS (and Android) - its a real shame Unity doesn't report any error when this happens, but just draws a black texture :( Some form of feedback would have been really useful, and saved a lot of people a lot of time.
     
  8. GermyGames

    GermyGames

    Joined:
    May 20, 2012
    Posts:
    38
    Is there a way to change a sprite's scale using a Unity animation? Keyframing and changing the sprite's scale doesn't seem to change anything.
     
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes there is with an adapter. Drop me an email at support at unikronsoftware dot com.
     
  10. GREBENOTS

    GREBENOTS

    Joined:
    Jan 24, 2013
    Posts:
    44
    Agreed. As per my usual, I end up typing out my problem (getting it out of my head and onto paper), and then find the solution myself.

    Do you have a tutorial on how to manage the layers of sprites? I'm finding that changing the Z value is not working as expected.

    EDIT: Apparently its only buggered in the Scene view and not the Game view.
     
    Last edited: Apr 17, 2013
  11. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you set scene view to back orthographic, the result should be virtually identical to game view.
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  13. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
    I'm sorry if this has been answered before, but can you use Unitys built in lighting with 2D Toolkit? Point lights, or global light specifically, to light sprites and scenes?
     
    Last edited: Apr 19, 2013
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes you can. You will need to turn on normals generation and switch to lit shaders.
     
  15. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
    I want to kiss you on the mouth.

    I'm pretty new to Unity, but is this information in the toolkit docs? I sort of don't know how to do this. :p
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Its mentioned briefly in here:
    http://unikronsoftware.com/2dtoolkit/doc/reference/sprite_collection.html

    That's where you change the normals generation mode.
    After that, double click on the material to get to it, and change the shader.
     
  17. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
  18. BranDino

    BranDino

    Joined:
    Apr 12, 2013
    Posts:
    16
    Question "BetaTile Map" Gaps between Tiles: How do I eliminate gaps between tiles in tile map beta for a seamless tile map (is a solution available in this version-1.92-- or in future release) ? I have searched this unity forum and your other 2d tool kit forum for help without much luck (found some threads that were kinda of relevant..). I did find the following post which helped me to get a tile map working, perhaps you can include these additional steps in your official documentation "Tile Map Tutorial" ?
    ( http://unikronsoftware.com/2dtoolki...?PHPSESSID=u5pltd717dhdrc6us127foouk1#msg6405 ).

    Thanks again this Kit works great, purchased this Monday and already have my first level running with several layers!!
     
  19. GREBENOTS

    GREBENOTS

    Joined:
    Jan 24, 2013
    Posts:
    44
    Is there a way to change a sprite's collection via code?
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hey there,

    Have you tried this?
    http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,294.0.html
     
  21. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can't "just change the collection", but you can change collection sprite at the same time.

    sprite.SetSprite(...) has an overload just for this.
    http://unikronsoftware.com/2dtoolki...sprite.html#a2a07db9fdd5df4739ffd956d83f12454

    If you wanna switch to a new collection, but keep the same named sprite, you can of course do something like this:
    sprite.SetSprite(newCollection, sprite.CurrentSprite.name);
     
  22. tylernocks

    tylernocks

    Joined:
    Sep 9, 2012
    Posts:
    256
    For people wanting to buy this pack don't, it sucks.......just kidding, THIS IS THE BEST 2D FRAMEWORK IN UNITY3D, you want to do 2D in unity, don't waste time, get 2DToolkit, Unity3D should hire this guy, and make this be default in unity3D. I have only one (Minor because its pretty easy) complain, it needs more tutorials, showing how and what to do.
     
  23. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Glad you like 2D Toolkit :)

    More tutorials are coming after 2.0 is out - we're working on a "complete game" tutorial. Its a simple game, but should cover all the basics.
     
  24. BranDino

    BranDino

    Joined:
    Apr 12, 2013
    Posts:
    16
    Yes I tried "can fix it by switching "Pad method" to "Extend" in the sprite collection editor." and unfortunately that had no affect? I can give it another shot..but is there another possible solution? the original image was a Tiff with alpha. thanks

     
  25. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
    ETA on that?

    And could you help me figure out this lighting thing? I must be doing something wrong as I can't get any of my sprites to be lit by Unity lights. It works fine when I apply them as textures to things like cubes, but not when they are sprites.
     
    Last edited: Apr 20, 2013
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hard to tell without seeing results or knowing more about your atlas.
    Are you using point filtering? Mipmaps?
    You can email support if you prefer. (support at unikronsoftware dot com)
     
  27. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I'm not announcing any dates - every time I've announced a date, I've for some reason or other had to crunch really hard to meet it! Trying to avoid that this time around.

    With lighting, do you get any change at all? You might have to use pixel lights to get the sprite to light "inside" the sprite. All this depends on how big your lights are and how big your sprites are. Also, make absolutely sure that your material is set to a lit one, and that you have normals. You can verify the shader by clicking on the sprite and looking at the shader on there. You can verify the latter by double clicking the mesh in the sprite meshfilter, and then look at the result. If you don't have normals, you should get a warning in the console about it.
     
  28. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
    Thanks!
     
    Last edited: Apr 20, 2013
  29. Android Matt

    Android Matt

    Joined:
    May 24, 2012
    Posts:
    61
    I was wondering if this might be useful for my particular situation...

    I am working on a 3D strategy game that uses a tile map consisting of 2D-hexagons. Given that my tile map is just a series of 2D textured hexagons, I'm hoping that this might be a good way to optimize this.

    At the moment each tile is a game object, with it's a material which is determined programatically from a list at the map generation stage. While this works perfectly in terms of the logistics of programming, and the resulting game play, I obviously have a lot of draw calls that I now wish to reduce.

    Is it likely that I might be able to employ 2D toolkit to deal with assigning textures to the tiles on my game map? I tried to recycle some basic sprite manager code from an old tutorial so that I could use just one material, regardless of the type of terrain on the map, and instead select a texture from a large atlas of terrain textures, but I couldn't get that to work with dynamic batching so it actually increased my draw calls!

    One last question: I'm using JS for all my scripting - will this work with that?

    Thanks!

    Matt
     
  30. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    44
    Hi guys!

    I have a question about a specific use case and was hoping to get an answer that will make my life easier.

    I come from a more traditional/code-only background and I'm used to setting up the scale of my sprites manually using the world coordinate system. I'm currently working on a prototype in Unity (for the first time, been at it about a month) and now that game mechanics are in and working with crappy programmer art, I wanted to get all the pixel perfect assets in.

    My issue is that to draw pixel perfect, I need to change all my sprite object scales back to 1 and leave the sprite scale as 1 in the sprite sheet.

    If I want to draw in world coordinates (aka not change my object scales) I need to calculate the right scale for each sprite in the sprite sheet which feels backwards to how tk2d was meant to be used.

    The reason why I have always worked in world coordinates is that I could just swap assets behind the scenes to target a new resolution. No code changes and the sprites are pixel perfect on a different screen/platform, yay! For example, if 1 world unit is 10 pixels and my character is 5 units high, I drop in a 50px high sprite. If I want to target a platform where 1 world unit is now 20 pixels, I simply swap out the sprite for a 100px version and change nothing else to get pixel perfect rendering.

    So ideally, I'd like to (without having to set scales for each sprite individually) have the sprites be scaled by the world coordinate system I have set up so that I can use the world scale to size them in code and have them look pixel perfect.

    Is there an easy way to achieve this?

    (I'm also posting this on the tk2d forum so if you see it twice just answer in one spot!)
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    1. 2D hexagons - there are a few tools at your disposal here which could help. The main one is that you can actually draw custom sprites shapes (i.e. draw a hexagon to tightly fit your sprite data, so you're not wasting a ton of overlapped sprites edges.) Sprites in 2D Toolkit don't need to be square, and aren't limited to 2 triangles (1 quad). They can have as many faces as you need, within reason of course.

    2. Import all your sprites into a sprite collection, and create your sprites using SetSprite("name") instead of setting the material. They will all use the same material, and that should be fine. 2D Toolkit uses dynamic batching, but this definitely works.

    3. 2D Toolkit works fine with JS, but you will need to run this first. http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,33.0.html
    Please note the samples are all in C#, but should be easily translateable to JS. There are a few JS conversions on our forum.
     
  32. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hey Andrew,

    I saw your post on our forum first so I've replied on there.
     
  33. Android Matt

    Android Matt

    Joined:
    May 24, 2012
    Posts:
    61
    Thanks for the quick (and detailed) reply! My map is algorithmically generated at the beginning of the map scene, so all the hex tile game objects with their own individual meshes are instantiated by a function call in the Awake() function. The texture has to be set after that algorithm is complete. Can you think of any reason why my methodology might not be compatible with assigning sprites as you describe?

    I'm expecting to have about 100 different terrain textures (mostly variations on a theme), with all of the tiles rotated by a random amount in intervals of 60 degrees (so the hex still tessellates and adds an extra degree of randomness to the map). If I understand correctly, I should be able to render all that with only one draw call (assuming I used a single draw call shader)?

    It sounds like a great solution to my problem. If I can render all that with far fewer draw calls, in a 3D game, with any shader that I choose, rotate them all by different amounts, and script it all in JS....then I think you have yourself another customer ;)
     
    Last edited: Apr 23, 2013
  34. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Its fine instantiating all that in Awake, but is there any specific reason you assign the texture AFTER you generate the map? The reason I'm asking is the normal 2D Toolkit workflow is to create a sprite collection first, and to create sprites that use this sprite collection. Its a minor change in your workflow, but the idea is that when you create a sprite, it will contain the subrect of the texture you need. The sprite collection re-atlases your sprite (possibly not needed in your case, but still there will be benefits like creating non-square sprite geometry, etc)

    If your map is static, then you should probably create a static sprite batcher and assign the sprites in there. It'll be massively quicker to do that than to generate however many gameobjects in the scene. The static sprite batcher gets baked into one mesh, so you'll be guaranteed one draw call. You can rotate sprites in here by any amount, either visually or programmatically. Though its not officially documented, there are examples on our forum on how to do this from code.

    You can script in JS, as long as you run the setup script first.

    Again, we have a pretty robust support structure in place. If you run into any issues, post on our forums (http://unikronsoftware.com/2dtoolkit/forum/) or email support - we generally reply within 24 hours, often much quicker :)
     
  35. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
    When creating an animated sprite, can I import an animated gif and use that for each frame? Or can I use say, a sprite sheet? Do I *have* to import each individual frame as its own texture to animate it?
     
  36. Android Matt

    Android Matt

    Joined:
    May 24, 2012
    Posts:
    61
    The reason that the texture is assigned after the map is generated is mainly just as a result of me developing this in a modular fashion (not enough foresight/planning to fully appreciate what I may need to do next!). It does still happen in the awake function, just after the hex map generation.

    Essentially what happened was that I had coded it so that a game object with a hex mesh was instantiated at all the required locations to form the full extents of the map (with the renderer turned off for all those hexes which are not visible at the start of the game), with each of these game objects being stored in a 2D built-in array. I then iterated through the 2D array with my terrain generation algorithm and set all the textures based on what was determined to be an appropriate terrain at that location. Having it set up like this allowed me to turn the renderer on and off for each hex depending which players turn it is. Will I be able to selectively do that with 2D toolkit?

    I can't run the terrain generation algorithm in it's current form until the game objects exists. I could alter it to save a 2D array of the desired terrain types and associated textures (+ random 60 degree rotation) prior to the hex map generation since I will at least know the size of the map at that stage. I could then apply the appropriate texture with as per the 2D Toolkit workflow?

    Having the map consist of game objects is really useful for me, at least of for the way my brain works, it seems very intuitive and debugging is really straight forward. The map actually generates very quickly, and the game objects only store a few bits of data each - no physics calcs, no complex update functions, so it all seems pretty efficient. If I can avoid moving away from my game object oriented workflow then I would much prefer that!

    The sprite batcher still sounds interesting though - perhaps both methods could be employed? Keep the game objects for all my background game logic, but use the single baked mesh for rendering...

    Thanks!

    Matt
     
    Last edited: Apr 23, 2013
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can import an evenly divided sprite sheet, but not a gif.
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The static sprite batcher was just a suggestion - 2D Toolkit generally doesn't force you to work in any particular way, and is quite flexible. You can build individual sprites, which are just gameobjects. You can mix and match too, so that isn't an issue at all.

    If you can send me a screenshot of your texture, then maybe I could give you some better suggestions. support at unikronsoftware dot com if you want to get in touch. With 2D Toolkit you create an atlas out of all the textures you'd use, and then create sprites from these textures.
     
  39. Android Matt

    Android Matt

    Joined:
    May 24, 2012
    Posts:
    61
    Thanks for all your help! I'm going to have a thorough read through the manual now that I that I know that it is appropriate for quite a few things I wish to do (not just stuff related to my Qs here!). Once I've got a better handle on it I'll buy the toolkit and have a go at implementing stuff.

    Cheers,

    Matt
     
  40. GREBENOTS

    GREBENOTS

    Joined:
    Jan 24, 2013
    Posts:
    44
    Can we get an explanation of how to use the loadable asset feature? Syntax etc. :p
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The loadable asset feature isn't documented properly as it hasn't been tested thoroughly outside the scope it is currently being used in, i.e. platform sprite collections. If you'd like some pointers on how to use it drop me an email at support at unikronsoftware.com, and I'll write up a few lines about it. It is straightforward and should work fine, but no guarantees it wont blow up your computer!
     
  42. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    @unikronsoftware
    My game has 1x and 2x textures with 2dtoolkit platform system.
    I'm having the following issue. I have a scene with some sprites (all preloaded on the editor).
    When I put in Awake: tk2dSystem.CurrentPlatform = "2x";
    It doesn't change the textures /quality.
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @spartan - is this just in the editor or in game as well? This should be called BEFORE anything is loaded, so make sure your awake function is sequenced before all the sprite stuff gets loaded in...
     
  44. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    It's happening in game editor. Some SpriteCollections are shown in HD (@2x) but others are in low quality. I've verified all collections and have both 1x and 2x platform.
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That implies that tk2dSystem.CurrentPlatform may not have been set before some of those sprites are loaded in.
    Try having an empty scene with just the script setting tk2dSystem.CurrentPlatform, which then loads your first scene. Does it work if you do it like that?
     
  46. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    Thanks unikron, making an empty scene to set tk2dSystem.CurrentPlatform worked great.
     
  47. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If that works, it implies that your script isn't executing at the right point in the other scene. Check the script execution order that it is well before any of the tk2d scripts.
     
  48. spartan

    spartan

    Joined:
    Mar 10, 2010
    Posts:
    174
    The script is on the tk2dCamera, executing the platform selection on Awake.
    But due other sprites are already on the scene (which is normal), seems that Unity is loading/executing other objects before the tk2dcamera.
     
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Have you made sure your script is sequenced correctly in here?
    http://docs.unity3d.com/Documentation/Components/class-ScriptExecution.html
     
  50. spg2000

    spg2000

    Joined:
    Apr 28, 2013
    Posts:
    1
    Hi - I'm considering using 2DToolkit for a game I'm working on that is based around a large hexmap - thousands of tiles. This represents the environment and will also have characters/entities/etc. moving around on it. Does the map editor support hex sprites? Is it feasible to set this up with each tile being a game object? Is it possible for 2D Toolkit to prevent wasting sprite edges? Any tips for how I should set this up?