Search Unity

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

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
    Just in case something went wrong, could you try deleting the index and trying again? It should be in the root of the project called -tk2d.
     
  2. ivincent

    ivincent

    Joined:
    Jan 16, 2012
    Posts:
    16
    Does that file need to be writable? We have our entire project under source control and files that are not checked out for editing are marked as read-only. Could that be causing issues with 2DTK?
     
  3. ivincent

    ivincent

    Joined:
    Jan 16, 2012
    Posts:
    16
    That was the issue. I removed the file from version control and now the sprite collections are showing up. Thanks for the help!
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Best to keep it out of vc. It is regenerated when it is missing, and needs to be writable when a new asset is created or modified. Glad that's fixed the issue!
     
  5. pavlito

    pavlito

    Joined:
    Nov 27, 2007
    Posts:
    136
    Hi.

    I'm looking for a way to increase performance of our game as much as possible.

    1. Could you give some information on what shaders to use for best performance and which compression method for textures with alpha channel (I couldn't find any info about it in the documentation).

    2. Is there best practice when it comes to static sprite batchers? Is it good to have a bunch of them or is there an optimal number? The documentation says when 1px of the batched sprites is visible to the camera, the whole batcher is rendered. I'm having doubts on how big the batchers should be, meaning how many sprites they hold. Is it good to have a static sprite batcher for e.g. a platform and then duplicate this platform all over the level?

    3. How much does a polygon collider affect the performance? Is it good to make each sprite have its own polygon collider or should I batch sprites e.g. platform (sprites: left, middle, right) and then add a capsule collider to that batcher afterwards?

    Thank you.
     
  6. unikronsoftware

    unikronsoftware

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

    Firstly, have you profiled the game to see what the bottlenecks are? Also, what platform are you dealing with?

    1. With regards to the shaders, both the shaders provided should be "as fast as it gets" as they are both single pass shaders. The only way you could make them faster is to make them solid, and then you should see quite a huge improvement. But this is unlikely to be suitable unless you're building a tilemap or something like that. For textures with alpha, the best format will be determined by your target gfx hardware. Say its on PC, DXT5 would be a good bet. Again, depends on what you're targetting.

    2. With the static sprite batchers, it really depends on the type of game you're creating. If its the PrinceOfBalls game in your signature, then I would suggest static batching one page or half a pages worth of sprites. Basically with half a page, you'll only be drawing 3 of these at a time max, so the wastage will not be significant.

    3. Polygon colliders are fine, but ideally you should have as few as possible of them. The larger the polygon collider is (and the fewer of them you have), the better off you'll be. Physx does its own spatial partitioning, so the performance doesn't drop when your mesh gets big. An efficient way to do this is to simply use poly colliders, merge them using the static sprite batcher. Try to avoid polygon collider on your player - instead prefer primitive colliders or convex hulls (polygon colliders marked as convex, I can't say for certain how efficient it is in Unity; I am basing this on my experience with another engine with low level PhysX integration).

    Hope that helps, and if you want to discuss this in more detail, feel free to drop me an email.

    Cheers,
    unikron
     
  7. Mark_T

    Mark_T

    Joined:
    Apr 25, 2011
    Posts:
    303
    Hi,
    I`ve seen you increased the price to $65.00.
    Do you plan a Paypal paying method?
    Thanks.
     
  8. unikronsoftware

    unikronsoftware

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

    The price increase was a difficult choice, but we really did need to justify the increased amount of time and resources we are spending on 2D Toolkit. It was either that or to reduce the time we spent supporting and developing new features for it, and we decided on the latter. We did keep the original price for nearly 10 months, and I expect it to stay at this price for at least a similar amount of time.

    We do plan on creating an external store for those who can't use the Asset Store, and we have the infrastructure to distribute updates and such, but that isn't in the immediate plans - the asset store handles a lot of the nasty stuff, like VAT and refunds and such, and it would obviously increase our workload dealing with another storefront.

    Is there any particular reason you'd like to use Paypal externally instead of through the Asset Store? If you have difficulty purchasing through the Asset Store, contact us using support at unikronsoftware dot com and we'll work something out.

    Cheers,
    unikron
     
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  10. gabidof

    gabidof

    Joined:
    Jun 15, 2011
    Posts:
    14
    Hi Unikron,

    One question, do you change the public attribute of the textmesh class?, because i can't get the spacing attribute work.

    Thanks!
     
  11. Neverbe

    Neverbe

    Joined:
    Jun 29, 2010
    Posts:
    34
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That was mainly because I didn't expect anyone to want to change that outside the inspector. Easily fixed by adding a couple of accessors and using those instead -

    Code (csharp):
    1.     /// <summary>Additional spacing between characters.
    2.     /// This can be negative to bring characters closer together.
    3.     /// Call <see cref="Commit"/> to commit changes.</summary>
    4.     public float Spacing { get { return spacing; } set { if (spacing != value) { spacing = value; updateFlags |= UpdateFlags.UpdateText; } } }
    5.     /// <summary>Additional line spacing for multieline text.
    6.     /// This can be negative to bring lines closer together.
    7.     /// Call <see cref="Commit"/> to commit changes.</summary>
    8.     public float LineSpacing { get { return lineSpacing; } set { if (lineSpacing != value) { lineSpacing = value; updateFlags |= UpdateFlags.UpdateText; } } }
    I've added these to the codebase, so you can safely start using them - it will be in the next release.
     
  13. unikronsoftware

    unikronsoftware

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

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
  15. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Absolutely. You can automatically generate box colliders for relevant sprites or draw custom polygon colliders per sprite if you wish, and the system will generate an optimized collision mesh from that. I'm currently updating the sprite collection editor to make it easy to deal with large numbers of sprites - I'll post more screenshots once thats done.

    All features which work with normal sprites work here, apart from multi atlas spanning - each tilemap has to be sourced from exactly one atlas.
     
  16. lmendez2

    lmendez2

    Joined:
    Mar 22, 2012
    Posts:
    1
    I was wondering if it's meant for the prefab connection to be lost when multiple sprites are committed to a sprite batcher? For example, what's happening is if I have a 'Brick' prefab and add 20 of them to the scene and then batch them and commit, and then decide to change the prefab, the changes I make to the prefab don't change those 20 bricks even upon edit. Is there any way to keep the prefab link, what's recommended?

    Thanks! Love the product btw.
     
  17. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes, that will happen, as the prefabs actually get destroyed - the only information that is retained is the spriteId. There isn't really any way around that, unfortunately, without increasing the memory footprint and processing time.

    Edit: Actually after thinking about it some more, I can actually see a really good use for this. The tilemap editor supports prefabs and spawning them in place of tiles, perhaps something like that could be extended to the static sprite batcher...
     
    Last edited: Mar 22, 2012
  18. Sammual

    Sammual

    Joined:
    Oct 28, 2008
    Posts:
    176
    Looks interesting, I am interested in the Tilemap editor as well. Does it support Hex tiles?
     
  19. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It can support hex tiles with a few lines changed, but it isn't in the first release as I won't have the time to test it, etc. I will be happy to show what needs to be changed to make it work though.
     
  20. Neverbe

    Neverbe

    Joined:
    Jun 29, 2010
    Posts:
    34
    Can I combine 3D stuff with 2D stuff? Will 3D elements collide with 2DToolkit sprite?
     
  21. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yup. 2d toolkit uses Unity colliders so it will just work.
     
  22. Neverbe

    Neverbe

    Joined:
    Jun 29, 2010
    Posts:
    34
    Good, I'll buy it as soon as the tilemap editor will be released ;)
     
  23. Mikie

    Mikie

    Joined:
    Dec 27, 2011
    Posts:
    367
    It says 65 on the assets store.
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Sorry, the forum page was out of date - we increased the price after 9 months to justify all the additional developments and features that have gone into it. Even more features are going into 2D Toolkit in the near future - the tilemap editor is currently in beta, and an interface update is in the works too!
     
  25. Wild-Factor

    Wild-Factor

    Joined:
    Oct 11, 2010
    Posts:
    607
    By announcing in advance your price increase, you would have probably increase your sales...
    I would have bought it "just in case". Now I can hesitate :)
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hercule - that is a very good point. I'll keep that in mind, though I don't intend on increasing the price for the forseable future. Thats really good info for the next product, thanks :)
     
  27. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    Will you manage to release the tilemap editor the next week?
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The plan is to get the Tilemap editor feature complete next week. Whether or not I can release it is a different matter entirely, as it really depends on how well the tests go. It is available to all registered users, though, and by beta standards I'd say it's very usable.

    We're now in the polish phase for the new sprite collection editor, it's now really really easy to create and manage large numbers of sprites (as you'd find in a tile sheet), and the tile sheet import is vastly improved and now supports padding and margins. This is really a prerequisite for the tile map editor, hence the delay. Also, you can now multi edit sprites, and also apply collider setups on multiple sprites simultaneously - with the previous system, setting up 120 sprites in a tileset, while possible, would have been completely impractical.

    So, the plan is to finish this, and barring any show stopper bugs, we'll be submitting 1.60 with this new editor today or tomorrow, and work on getting the Tilemap editor feature complete. I'm not going to promise any set times for it to be ready, but I'll be posting updated betas much more frequently once 1.60 is out of the way.

    Unikron
     
  29. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    I think I asked this once before but got sidetracked. I believe it is possible to put a rigidbody component onto the 2D toolkit sprite, but will the dragrigidbody script work on it as well? I'm having some problems getting this to work, I sort of need to be able to drag a 2D sprite and have it knock other sprites out of the way and I'm wondering whether anyone had done this and figured out how it works.

    Any help would be greatly appreciated.
     
  30. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    Thank you for your answer I'll wait for the official release.
     
  31. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    282
    @unikron
    I have detected a problem in the tk2dButton.

    When it is set to active=false, while is pressed, your function dont work more when it go back to active=true.

    To fix, add this lines to tk2dButton ( in advantage that you will release an update )
    Code (csharp):
    1.  
    2.     // Fix the set active=true
    3.     void OnEnable()
    4.     {
    5.         buttonDown = false;
    6.     }
    7.  
     
  32. Suminsky

    Suminsky

    Joined:
    Aug 11, 2011
    Posts:
    50
    Stupid questionS..
    If I buy this on the asset store, Will I be able to update always? Just to make sure ;D

    I have a concern about sprite animation in flash builds, I tried everything and didnt manage to make it work(just cant update uvs), does 2d toolkit managed to make this work? I tested in chrome and ie with the last flash plugin version.

    If I buy this, can I use it in other computers or its a dead fixed package importation? How this works?
     
  33. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Cheers for the fix, sandolkakos. I will add it to the next release.

     
  34. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes, updates will be free, and you'll be able to update for as long as we release updates. You can also register on our forums using the invoice number from the asset store - you'll be able to get updates, betas, code snippets, etc. from there.

    I've not had any problems with the flash player, but its been a while since I tested it - I'll test it the next time I get a chance (with the latest of everything) and get back to you on that.

    The asset store lets you download on other computers as long as you sign in. You're obviously bound by the asset store terms conditions.
     
  35. unikronsoftware

    unikronsoftware

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

    I don't see why this wouldn't work. I'm not sure which dragrigidbody script you're using - we rolled our own when we needed something like this. Don't forget to constrain the rigid body so it wont move in Z and only rotates on the Z axis, otherwise you'll have it flying about all over the place.
     
  36. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    Can the tiled layer support parallax scrolling?
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You could do that, yes. You won't be able to use internal layers, the best way to do this is to create multiple tilemap objects and use them as layers. Using the parallax script which is in the private support forum is probably the best way to do this.
     
  38. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,121
    Hi! I brought this up a while back- the source (separate) images are being exported as well (v 1.51)- we do not reference the spritecollections in the scene, just tk2dSptite/tk2dButton/etc
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi yuriythebest - perhaps my response got lost in the threads before. The sprite collection data object used by the game components dont have any link to the original sprites whatsoever and can't possibly add the source images as a dependency. The only object with a link to the source images are the sprite collection objects, and in one version, the index object. If any of these are in a resources directory, or are linked to any objects within a scene, then you'll get all that baggage linked in. Can you confirm you haven't done any of this?

    Secondly, you're on a very old version of 2d toolkit. Not that it should matter, just letting you know.

    Too keep this conversation from being lost in the thread again, could you email me - support at unikronsoftware dot com.
     
  40. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,121
    the resources directory? Indeed. I have spritecollections in the resources folder which I load when need be (so they aren't all instantly loaded into memory)- ahah, so seems to avoid this I should keep the spriteCollection out of the resources folder, while keeping the "data" and maps themselves inside?
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The only thing which should be put in the resources directory is the data object itself. That alone will pull in all the required elements. But you can simply copy the entire data folder into there, no problem.
     
  42. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,121
    Are you sure? will be atlasses not be "stripped"/not included from the project?
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The data object has a reference to the material the atlas texture, and the dependencies will automatically be pulled in to the build.
     
  44. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,121
    cool thanks!!!
     
  45. hidingspot

    hidingspot

    Joined:
    Apr 27, 2011
    Posts:
    87
    I tried this solution, but 2d toolkit doesn't really support it. 2d toolkit has an "UpdateMaterial" function in tk2dSprite which changes any manually assigned material to that of the sprite collection. This means that setting up several materials to have different render queue's just gets reverted by 2d toolkit. One way to get around this would be to use a different sprite collection for every different render queue setting, but that is far from ideal. Any other ideas?
     
  46. sabba2u

    sabba2u

    Joined:
    Feb 3, 2012
    Posts:
    42
    We've got a 2D game setup where we have a foreground texture that we read in via GetPixels(), and then we generate a collision array grid from that. I am trying to layer 2d Toolkit sprites for enemies/collectables on top of the whole map, which works just fine.

    But in order to be able to write the data back to the collision array I'd need to be able to GetPixels/SetPixels() because that is the way we have our collision handler setup. So, if we want to drop a block onto the level, we GetPixels() the block texture, and then setpixels() in the appropriate position on the map as well as write to our collision array.


    However, I was wondering, is there a way / what would be the best method to GetPixels() on a 2dTK sprite? I tried looking through the source and thought I might have gotten luck with .color but that came up empty for me.


    So things I've tried...

    Texture temptkSpriteTexture = tkSprite.renderer.material.mainTexture; //only results in getting the whole atlas, not the current sprite



    Now, I'd like to be able to get access to only the current texture on the sprite gameobject.... as in only the sun or crate from the demospritecollection for example.

    So I can assign it:

    public tk2dBaseSprite testSprite;


    and then something possibly to do with testSprite.colors ?


    Things I have yet to try... that should work:

    Worst case scenario I would have to read in the texture atlas and get the coordinates manually for the sprite I am interested in, GetPixels() and SetPixels()...

    Or possibly renderer.sharedMaterial?



    Thank you, and any help would be appreciated.
     
  47. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That was a fairly recent addition. Now that we have our new sprite collection editor, we can probably go ahead and add support for multiple materials. However there might be a better way to do this. Are you trying to create a parallax scrolling layer? If you are, then we have a solution posted in the private support forum which will let you do this, while keeping ortho cameras. So the first question is, really, are you trying to create parallax scrolling?
     
  48. unikronsoftware

    unikronsoftware

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

    With regards to getting pixels - this is generally a bad idea and should be avoided. In order to read pixels, you'll have to perform the UV transformation and read out of the main atlas directly. This isn't particularly bad in itself, but the performance won't be great. Also, this won't be possible in Unity unless you use 32 bit uncompressed textures.

    I'll just briefly go through the steps here.
    * Make sure dicing is off on your sprite collections, this will introduce a lot more complexity to your system.
    * Get the atlas texture through renderer.sharedMaterial.mainTexture
    * Make sure this texture is set to readable (switch type to advanced, tick "Read/write enabled", and make sure its type is "Automatic Truecolor")
    * Get your UVs and transform to a pixel range (sprite.GetCurrentSpriteDef().uvs) multiply those numbers by the texture dimensions to get pixel coordinates.
    * Read individual pixels using these numbers

    Having said all that, I think reading pixels is a Bad Thing to do generally, if I knew your needs in more detail, then perhaps I could suggest alternatives. Feel free to drop me an email at support at unikronsoftware dot com, should you wish to discuss this further.

    Cheers,
    unikron
     
  49. thecosmicboy

    thecosmicboy

    Joined:
    Mar 29, 2012
    Posts:
    2
    I'm having problems after the update to 1.6,

    When I create a new animated sprite and assign the sprite animation I have created to it,
    when the animation plays some frames are warped in different sizes.

    It is not warped in the sprite collection or in any of the sprite animation settings.
    Can't get my head around if its a bug,
    It never happened in the older version and Ive retried it many times with the same results.

    Also the autofill feature does not work with the new names assigned to individual sprite frames taken
    from a spritesheet. 0x1 1x1 3x1.. etc

    Cheers if you can help :)
     
    Last edited: Mar 29, 2012
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    Please get in touch via email - I will need more details for the first issue. With regards to the second one, I will be happy to provide a patch which will revert the naming scheme - I clearly overlooked the auto fill. The support email address is support at unikronsoftware dot com.