Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

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
    1. No it won't be feasible setting this up with each tile being a gameobject. You will run into serious bottlenecks once you go beyond a certain number of gameobjects. The tilemap system in 2D Toolkit will collapse the tiles into one or more meshes though, so this won't be a problem there.

    2. The tilemap system in 2D Toolkit doesn't officially support hex tiles, but hex tiles are more or less the same as isometric tiles with different offsets, and you can configure it to work fine. 2 caveats
    - it doesn't correctly handle overlapping partition edges (you are likely to get sorting errors), but this is only an issue if your tiles overlap with adjacent tiles.
    - the cursor when painting tiles is drawn as an isoemetric rectangle. I did have hex drawing at some point, so I might be able to dig up the code.

    3. With 2D toolkit, sprites don't have to be square, so you can draw an optimal hexagon shape for your hex tiles to save overlapping fillrate at edges, but it doesn't yet support extracting a hexagon from the actual source to optimize texture space.

    4. About setting it up, its pretty much the same as any normal tilemap. There is a basic tutorial here:
    http://unikronsoftware.com/2dtoolkit/doc/tilemap/tutorial.html

    One addition:
    - set tile type to isometric in "Tile Properties". Adjust size so the hexagons fit perfectly.
     
  2. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    For some reason text mesh won't escape \n properly when inside a public string from Unity Editor such as:

    In Editor: S [The string\nwon't escape]

    Code (csharp):
    1.  
    2. public string s;
    3. textmesh.text = s;
    4. textmesh.Commit();
    5.  
    even if the max chars is more than enough.

    Is this a bug or a limitation or am I doing something wrong?

    EDIT: Never mind. Did some digging and found the alt+enter line break shortcut for editor string windows. Does the job. The problem only occurred because I was switching some fonts from NGUI to tk2d and NGUI appears to escape the \n automatically.
     
    Last edited: Apr 30, 2013
  3. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you're using it in your own string, the solution you above is far more efficient than processing escape codes in the textmesh as it doesn't involve escaping at all. Alternatively, when assigning your string you could do this... textmesh.text = s.Replace("\\n", "\n"); but that will allocate memory.
     
  4. bjohnson8704

    bjohnson8704

    Joined:
    Jan 30, 2011
    Posts:
    54
    We're using tk2d to create a simple mobile game in order to learn how to properly handle all of the different resolutions and other aspects of development. The way we currently have our scene set up is with multiple cameras to render different parts of the game with some being 3d objects rendered on a regular unity camera and then multiple tk2d cameras to be able to properly layer all the objects(1 for the background, 1 for the foreground and 1 for the GUI with the regular unity camera depth positioned in between the background camera and foreground camera). This gives us the desired results and allows us to use the resolution overrides to easily position the game elements for the multiple resolutions, however it seems that having multiple tk2d cameras is causing the game to slow down to where it's basically unplayable on my testing device(iPod with retina). Should this be the case? Everything seemed to work fine before adding multiple tk2d cameras, so I'm assuming that is the root of the problem, but that's just a guess on my end. Or could this slow down be due to the fact that we're building the game at 4x scale before adding in the 2x and 1x scales so the atlas size is currently twice the size that is needed on the testing device and the multiple cameras only compounds this issue for some reason? I'm sure there's a more proper way to handle things than what I'm doing, but I haven't really been able to wrap my head around the whole multiple resolution support aspect of development. Any help would be greatly appreciated!
     
  5. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Hey there. I don't know, but I'm sure it's a topic which has been already discussed a lot...but i need to know:

    I am working with .PSD Files/Sprites. For the work with 2D Toolkit, what are the best Importsettings (for a mobile Game - iOS/Android)? Currently I am using this setup:

    $bildschirmfoto_2013-05-01_um_20_06_45.png

    Should I consider change some settings?

    Edit:

    And i want to know how I can use the CrossFade with Animations? Is that even possible?
     
    Last edited: May 1, 2013
  6. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    With PSDs - you end up importing them into a sprite collection anyway, so it doesn't really matter what importsettings you use. What does matter though, is how Unity reads the PSD - long story short, if you're saving the PSD from photoshop, alpha channels / transparency tend to work a LOT better if you simply save a copy as PNG.

    You can't crossfade with animations - that will require creating 2 sprites on top of each other.
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The tk2dCamera doesn't add any additional cost, but you could do things that implicitly add cost
    1. What clear mode do you use with your other cameras? Ideally, use "Don't clear" on everything except the first camera.
    2. Your layers are all set up correctly, that you're not drawing everything multiple times, right?

    To debug this I suggest turning off all cameras, and then simply use one camera, turn on all layers on the one camera to see what the cost of everything is, and then add the cameras one at a time, keeping a close eye on draw calls and overdraw.
     
  8. bjohnson8704

    bjohnson8704

    Joined:
    Jan 30, 2011
    Posts:
    54
    Thanks for the response. :) My issue was that I had multiple camera's using clear flags other than "Don't Clear". Once I changed to what you suggested, all was okay again. Thanks again! And thanks for making such an excellent tool :)
     
  9. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Allright, thank you very much! Well I am using some PS-Actions in order to Stamp Alpha and get rid of Halos and whatnot and it works quite well: http://technology.blurst.com/remove-white-borders-in-transparent-textures/

    Another question:

    Is it possible to achieve something like this with the Fontsystem/ TextMeshes? :

    http://www.youtube.com/watch?v=J-OKIlcLDgk
    (go to 0:55)

    In the Video you see a screen where the words are displayed character for character with a certain speed.
    I want to make something like that in my game. And when the Player hits a certain Button, the whole text should be displayed at once.
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The text stuff is pretty much game logic - you make it append one character at a time and update the text mesh. You can certainly do it with 2D Toolkit.
     
  11. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Great! :D Thank you!
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Just so its clear - I'm not implying that 2D Toolkit will do it for you, but that you can write a little bit of script to make it add one character at a time, etc.
     
  13. shiraz888

    shiraz888

    Joined:
    Mar 20, 2013
    Posts:
    1
    I'd like to create animation cut scenes with sprite toolkit. Basically, in the animation editor - it would be awesome if there was a way we could add an offset to each frame - so that for example our animators could create long animation sequences (ie, a dog walking around the screen or a bee buzzing around).

    Is this possible?
     
  14. petey

    petey

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

    Scaling sprites and text using .scale is super handy for keeping the drawcalls down, but I was wondering how could you handle a situation where your sprites are parented to another object that is being scaled?

    Thanks
    Pete
     
  15. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Yeah, I got that, just wanted to know if that is possible with the Font/TextMeshes in generel. I'm already working on a script ;)
    Thanks!
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No it isn't possible at the moment, but I will consider it for a future update as there has been more than one request. I suggest posting requests, etc. on our official forums - things tend to get lost in this forum thread. http://www.unikronsoftware.com/2dtoolkit/forum
     
  17. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    A few different options, and it really depends what you're doing.
    Sometimes its worth just biting the bullet and forgetting about the draw call increase.
    But in other cases, there might be a slightly better way of doing things...

    Email support for more details.
    There is a really hacky thing you can do which could magically make things work for you, but I really don't want to recommend that as a general solution.
     
  18. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,380
    Yeah, I think i'll just do that, I just thought I'd check that i wasn't missing some other way of getting it to work.
    Thanks
    Pete
     
  19. storatest

    storatest

    Joined:
    Apr 8, 2013
    Posts:
    8
    i had a problem, the camera wont redraw on my galaxy tab 7.0, every time the sprite in camera move or removed, it still there in camera and not removed, any idea?
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    What do you have the clear settings on the camera set to?
     
  21. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Unikron,

    The tk2d camera has got to be the most often asked about feature in your kit. It's like this cool ability to fly, that no one really understands properly. For the love of God... please do a Tutorial Video on it. It's been long overdue and as for the benefit to you, imagine not having to answer questions about it any more.

    As far as that goes, a few fresh tutorial vids seem long overdue anyway on some of the new features over the past year +
     
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hah. I agree. New video tutorials are certainly long overdue - the ones I had before aren't exactly tutorials, more like feature demos. There will be a new camera type in 2D Toolkit 2.0, so I'll probably do one demonstrating all of the different options there.

    If you or anyone else knows anyone who can product decent video tutorials, I'll be happy to hear from them :)
     
  23. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,380
    Hey Unikron,
    Just wondering if it's possible to bake the scale of a 2dTk item through a script?
    Thanks,
    Pete

    P.S. +1 from me for some tutes :) do it!
     
  24. storatest

    storatest

    Joined:
    Apr 8, 2013
    Posts:
    8
    the clear settings? it is depth only, the camera always work well on the 1st try, but when u close the application and re open it again, the problem starts
     
  25. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you're not clearing color, the color buffer will be undefined - in your case it looks like its not clearing it at all.
    You should clear to Skybox or solid color.
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    All you do is take the transform.localScale and put it into sprite.scale, more or less. It does some funky stuff for when there are a hierarchy of sprites in there, but you can check the code in tk2dScaleUtility.BakeRecursive. If your hierarchy is flat, then you only need to do it once.
     
  27. storatest

    storatest

    Joined:
    Apr 8, 2013
    Posts:
    8
    it's better now, just another sprite become blinking, how about the culling mask?
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Keep everything other than the ortho size at default values. If its blinking try moving it towards the camera slightly in the z.
     
  29. storatest

    storatest

    Joined:
    Apr 8, 2013
    Posts:
    8
    i tried all but still failed, the blinking is like all the sprite color will become like the skybox color in the camera defined, and sometimes it return to normal and changed again
     
  30. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    So its not drawing for a frame or two? You'll need to work out why - is it moving when that happens, or is the camera moving, or both? Are you animating the sprite? What is the z postion and whats the cameras z postion? What is the camera type?

    Hard to tell without actually seeing it, as it could be a large number of things causing it.
     
  31. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    40
    hello Unikron

    I wanted to ask you something regarding aligning a sprite automatically against a tiled background.

    I'm working on a sidescrolling platformer.

    I have a background with some tiles, and an animated sprite representing a question mark block (like in mario) which the player can interact with. Both the tiles and the block sprite are 8x8 pixels wide and tall (so the pixels look pretty big on-screen).

    So far I've been placing the question mark blocks by hand so they properly align against the tiled background. As you can imagine this is extremely tedious, since you have to zoom in quite a lot to be able to align the sprite pixels against the background pixels properly.

    So I was wondering if there's any way in which I could somehow make the block sprites align themselves automatically to the background tile behind it.
    That way I could roughly place the sprites by hand wherever I want them to be, and they'll automatically snap to the tile behind them (ensuring that the tile and sprite pixels are properly aligned).

    Thanks
    nacho
     
    Last edited: May 7, 2013
  32. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you're using the tilemap editor, then you get this automatically. If you're not, there isn't a built in way to do this, but you could write a simple editor script to do it... If its specific to your project, then it should be really quite simple. You could put that into the sprite editor GUI so you have a button to snap to closest grid.
     
  33. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    40
    ok I'll try making a little editor script then.
    thanks, and good job with the tile stuff, it's worked quite well for me so far even if it's in beta.
    nacho.
     
  34. storatest

    storatest

    Joined:
    Apr 8, 2013
    Posts:
    8
    the camera is ortho with the size 256, with tk2dcamera resolution override and native resolution 384,512. the camera z positon is in -150, the sprite in problem is side scroll background with z in 0 and one animated sprite with z is -50, i've try to move the sprite closer but nothing changes, if you change the skybox color into black, the sprite will become black and if u change it into white, the sprite also changed to white
     
  35. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Hey there, I have a question regarding the Memory Usage with 2D Toolkit :)

    So in my very first Level there are now over 100 Sprites (which are of coursed batches. I've got 4 Texture-Atlases, a nGUI-UserInterface and some other stuff. Around 8-10 DrawCalls). I'm structuring them like this: an Empty GameObject is called for example "PLATTFORM_01" and it has the SpriteObjects as children. In the Scene-View one can see the whole Level. The next Level will be much bigger and longer and I guess I can't handle it that way, can I?
    Should I deactivate/activate the Plattform-Objects (which will deactivate the Sprite-"Children") when the Objects are not/are shown by the camera in order to save memory? I'm asking because I'm targeting mobile devices :)
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That won't save memory. Unity will load all those assets in when they are referenced in the scene. If you need to "stream" stuff in and out there are a few ways to go about it. Resources.Load is one, the other is to additively load levels. The number of sprites don't really matter, its the total texture sizes that matters.
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you can, set up a repro case demonstrating the issue and send it to support at unikronsoftware.com.
     
  38. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Ah, I see.
    Hm, additively load levels is a Pro-Feature as far as I know, so not possible to use in my case, unfortunately :/ (Free-User)
    Now that you mention that it's about the texture size: what do you exacty mean by that? Is there something I shouldn't do?

    The SourceSprites I make are between 50x50 and 1000x1000 (most of the time NPOT). Then I put them in the Texture_Atlases.

    I'm just curious. I worked before with a mix of Uni2D and 2DToolkit and somehow it gave my at Build&Running a Memory-Warning in XCode. Then I setup the level again with 2D Toolkit only and I didn't got the warning. I just thought 2D Toolkit handles that way better, but maybe there was just an internal problem with Uni2D AND 2DToolkit.
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The source sprites don't matter - 2D Toolkit doesn't use them at runtime. The only thing that matters is how big your atlases are in the sprite collection and how much memory they occupy. So look at that, and work your way from there. You have a fair few tools at your disposal to optimize this using 2D Toolkit - 16 bit dithered atlases, dicing, etc.
     
  40. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    The Atlasses are all set to 4096x4096 in the SpriteCollection-Editor. After Creation I override the MaxSize and the Format in the Import-Settings.

    But when I change the MaxSize in the SpriteCollection it seems, that it has no effect on the outcome-size at all . In the Inspector the created Atlas-Texture is still 16 MB big, I changed it from 4096 to 2048. If I make the Atlassize smaller, it says it isn't able to fit the textures, so I don't have much choices there.
    I also used "Compressed" and "16 Bit DitheringAlpha" and "-NoAlpha" just to try out. Didn't change the size of the Texture at all.
     
  41. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    850
    Hi,

    Is there a way to use pixel perfect images sprites without making 1 unit = 1 pixel?

    My problem is that Unity's navmesh starts acting really weird with high numbers and since I have a 1024x768 "world", I'd like to make everything smaller into reasonable size for the navmesh but still keep my art pixel perfect.

    Thanks in advance.
     
  42. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287


    16 bit dithered / compressed wont change the physical size of the texture, but will change the size in memory. Ignoring mipmaps,
    An uncompressed 4096x4096 texture = 64MB.
    16 bit = 32MB
    compressed varies, but on PC, for instance = 16 MB

    It WILL make a huge difference to how many you can fit in memory at a time.
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes, just don't use the tk2dCamera.
    Set the target height to your target resoltuion height (1024x768 for example) and pick an ortho size. 10-20 works well for default physics.

    Create a normal orthographic camera at the same size, and the sprites from that collection will automatically be pixel perfect when you create them.
     
  44. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Allright, I changed the SpriteCollectionSettings of all SpriteCollections to Compressed now and it didn't had any effect on the Quality of the Sprites, only when I reduce the MaxSize/Format in the ImportSettings. So this is intended, yes?

    And is there a way to determine (without the Profiler) how much Memory is used by the Atlasses? Speaking of fitting in the memory: Only the Atlasses which are used in the current scene at the moment are used in the Memory, right?
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes only atlases used / referenced in a scene are used in memory.
    You can see how much memory a texture takes by looking at it in the inspector preview.
     
  46. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Alright.

    If I would configure the Atlas_Textures in Size/Format in the Settings the results would be ugly on the device. As told I used "Compressed" on the SpriteCollections which didn't affect the Quality of the Sprites on the Scene but also it didn't show any change of the MemorySize in the Inspector-Preview.

    Here is a look at the Editor-Log:
    $bildschirmfoto_2013-05-08_um_16_08_42.png

    (One bigger nGUI Atlas)
    2DToolkit-Atlasses: Two Atlasses with 16MB , one at 8MB and one at 4MB.
    And that's the first scene. The next scenes and its Textures will be about the same size.
    Is this too much for iOS to handle? (I am targeting ARMv7 devices: iPhone3GS upward, and iPad 1 to actual iPads)
     
  47. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Compressed in the sprite collection should should change the output - you did commit after that, right?
    I can't remember the limits on older devices - perhaps will be a good idea to check on answers.unity3d.com if there are any posts on there about that.
     
  48. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Ah, now I see where what I did wrong. I comitted the existent SpriteCollection. If I'm creating a new one with the same Sprites, choose COMPRESSED then I get the right result: RGBA Compressed PVRTC 4 bits. But it can't be done if the Atlas has already been made. Is this intended?
     
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No? It should be have exactly the same unless the reference to the texture is broken somehow.
     
  50. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,155
    Hm, I am sure I didn't brake it. Just for the test: did make a new SpriteCollection. Set to "Compressed", the result was a compressed Texture, than set it again to Uncompressed -> it stayed compressed, didn't change at all.
     
unityunity