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
    Hi,

    Yes, unity will load all referenced objects for you (how convenient!). If you need to refer to something but not have it load, you can load it by path using Resources.Load(...). That will guarantee that you are only loading what is absolutely necessary.
     
  2. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This is because the scale is too small for the default physics properties. You can change these in Physics Manager. Alternatively, you can make your scene "bigger". i.e. scale it up 10x - you can do this by increasing the OrthoSize in the Sprite collection. Then change your camera ortho size so it matches this value.

    I prefer to make the scene bigger and keep the physics properties at defaults.
     
  3. dead1ock

    dead1ock

    Joined:
    Jan 4, 2011
    Posts:
    31
    Awesome, that fixed my problem.

    What size do people usually use for Orthographic projection to get a good scale?
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We usually use around 10 if memory serves me correctly - seems to work pretty decently then.
     
  5. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    Yeah, I need it to not load initially.
    Okay, I've tried it this way:

    however Debug.Log always returns a "null". I've double checked the directory to make sure everything was correct, what am I doing wrong?
     
  6. felix_berninger

    felix_berninger

    Joined:
    Aug 19, 2011
    Posts:
    30
    i have the same problem, can you please go a little bit more into into detail on that? thx in advance
     
  7. sebako

    sebako

    Joined:
    Jun 27, 2009
    Posts:
    301

    try this:

    Code (csharp):
    1.  
    2.  
    3. // Sprite Collection Data from path SpriteCollections/name_Data/data
    4. public static tk2dSpriteCollectionData loadSpriteData(string name)
    5. {
    6.     Debug.Log (tk2dSpriteCollectionData)Resources.Load("SpriteCollections/"+name+"_Data/data", typeof(tk2dSpriteCollectionData));
    7. }
    8.  
    9.  
    remember to change to path to whatever you have put you collections data.

    regards

    -zem
     
  8. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    thank you good sir that worked!
     
  9. RyuMaster

    RyuMaster

    Joined:
    Sep 13, 2010
    Posts:
    468
    Hi! I've tried to use diffuse bump shader, but result on screen is always totally black sprite. I remember it was something about recalculateNormals - should I add it somewhere in the code?
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    In tk2dSprite.UpdateVerticesImpl and .UpdateGeometryImpl, add mesh.RecalculateNormals() after the bounds are calculated. This should give you the normals required for the diffuse bump shader.

    Cheers,
    unikron
     
  11. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This is because the sprite doesn't align to the pixel grid - Assuming your screen is 1000px wide and your sprite is 256px in size - if the origin of the sprite is at 275.3 pixels across, this kind of artefact occurs.

    To get around it, you need to calculate so your sprites fall perfectly within the pixels - you can do this by scaling with orthosize and screen height - check the sprite builder code to see how it scales the sprite down, and do the same for your coordinates.

    unikron
     
  12. RyuMaster

    RyuMaster

    Joined:
    Sep 13, 2010
    Posts:
    468
    Thanks a lot, it helped! For anyone else: you also need to recalculate tangets - Aras provided function for that.
     
  13. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    I'm using from the past months the ex2D this is a great interface and very simple to use! But some things are really boring:

    - Working with Asset Server, make everything a mess in every time someone add some thing in one atlas
    - Working with fonts bug a lot.


    How 2D Toolkit work with Asset Server? Many peoples working in the same same project?
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We don't use asset server - I use GIT on some other projects which use 2D toolkit and it has been OK for us so far, bar the occasional weird problem, which happens with normal Unity assets as well. Multiple people can't edit the same Sprite Collection simultaneously, though that should be less of a problem with Asset Server, as you can lock assets. I am interested in hearing other peoples experience with Asset Server, if anyone has uses it.

    unikron
     
  15. gabidof

    gabidof

    Joined:
    Jun 15, 2011
    Posts:
    14
    Hi, i'm using the plugin with uScript. I have 2 GameObjects (both Animated Sprites) with the Box Collider and Rigidbody. I need to do when the 2 collide with each other make the physics and change the animation for the 2 GameObjects.

    I have this error: NullReferenceException UnityEngine.GameObject.GetComponent[Transform] ()
     
  16. gabidof

    gabidof

    Joined:
    Jun 15, 2011
    Posts:
    14
    I'm already found the problem. Now the 2 GameObjects don't do the AnimatedSprite, nothing happened, don't detect the trigger.
     
  17. sebako

    sebako

    Joined:
    Jun 27, 2009
    Posts:
    301
    hey unikron,

    is it be possible for animated sprites to have an option in the inspector to delay the animation between frames?
    Would be awesome if you can implement that!

    Thanks in advance.

    -Seb
     
  18. unikronsoftware

    unikronsoftware

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

    An improved animation editor has been in our todo list for a while - while we will certainly get around to it, I can't really promise any dates. It won't be in the next 2 updates though.

    unikron

     
  19. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    For some reason:
    Code (csharp):
    1.  
    2.             data = Resources.Load("Root/Batches/Backgrounds/"+backgroundwhich+"_Data/data" ) as tk2dSpriteCollectionData;
    3.  
    Does NOT work. I don't understand why at all. I know it's the correct path, but it keeps returning null even if I debug it. Argh, this is bizzare. I've tried just instead of dynamic "backgroundwhich" just put "background9" and it doesn't work...erghhhh.
     
  20. gabidof

    gabidof

    Joined:
    Jun 15, 2011
    Posts:
    14
    Hi Unikron, i find this problem. When i tried to make the AnimatedSprite detect with the trigger event, the the tk2dAnimatedSprite doesn't do recognize the trigger, i don't know if are an issue from the last update or something like that.

    Thanks.
     
  21. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I have replied to your support email with a test scene which demonstrates how you do this. For the benefit of everyone else who is trying to do this, here are the steps required to load a sprite collection directly in code -

    1. Create your sprite collection
    2. Rename SpriteCollection_Data/data to something meaningful - you
    will only be able to access this by name, so give it a unique name.
    3. Move this file, and nothing else, into a Resources folder. For
    example, put it in Resources/sunflower_collection. The resources folder doesn't have to be in the root of the project, you can simply create a resources folder where your sprite collection is and store it there.
    4. You can load this sprite collection by doing
    tk2dSpriteCollectionData data = Resources.Load("sunflower_collection",
    typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;

    Note you DON'T need to enter the full path to the sprite collection, just the name you picked in step 2, WITHOUT any extension.

    unikron

     
  22. unikronsoftware

    unikronsoftware

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

    This seems to be working fine for me - can you test demo #5, and click the "Message" button. You should see a text message pop up at the bottom of the screen pop up when frame 3 is displayed.

    unikron
     
  23. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    Thanks, the support is wonderfull. I wish you brought out plugins just so I can give you more $$ :p
     
  24. Hao-Cher-Hong

    Hao-Cher-Hong

    Joined:
    Dec 15, 2010
    Posts:
    127
    Hi,
    I got a problem when using sprites + perspective camera
    i have many sprite at different depth ( z position )
    and sometimes the deeper sprite will render to forward and block the sprites which are more close to camera.
    If I use orthographic instead, it works fine without render problem.
    how can I solve this?
     
  25. raulsabirov

    raulsabirov

    Joined:
    Nov 7, 2011
    Posts:
    2
    Hi unikron.
    i try this, but all atlas are loading in 1 scene

    from Editor.log
    ***Player size statistics***
    Level 0 'Assets/Scenes/Main.unity' uses 1.7 MB compressed / 9.6 MB uncompressed.
    Level 1 'Assets/Scenes/1.unity' uses 0 B compressed / 0 B uncompressed.

    i just wont to some atlas load in 1 scene( when the game is loaded and user sees the menu)
    and other atlas load in 2,3... scenes (when user select some level)
     
    Last edited: Nov 7, 2011
  26. raulsabirov

    raulsabirov

    Joined:
    Nov 7, 2011
    Posts:
    2
    just solved it
    by setting parameter "First Streamed Level" ==100500, i.e. greater than first scene
     
  27. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Things like these can happen with perspective camera. You can try to avoid it by changing FOV, etc but there will always be cases where things like this can happen. The solution is to use multiple materials and material.renderQueue. This means having to add a material for every time you need to control the render queue. For more info, check this page: http://unity3d.com/support/documentation/Components/SL-SubshaderTags.html

    Unikron
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thanks for posting that. I hadnt encountered it before, but I'm sure it'll be helpful to others.
    Unikron
     
  29. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    Hi, I sometimes need to rename .png files in my project after they have been added to a Sprite Collection. I want the name change to be reflected across both the Sprite Collection and the Sprite Animation for consistency (and sanity!) sake.

    If I rename a .png in my project, the name change will immediately appear in the Sprite Collection's Texture Refs, but the old name will still appear in the Sprite Animation's drop down list and also in the Sprite Collection Editor's drop down list. I've tried pressing "Commit" on the Sprite Collection after the name change (is that even necessary after a filename change?) and I also tried rebuilding the index.
     
  30. Hao-Cher-Hong

    Hao-Cher-Hong

    Joined:
    Dec 15, 2010
    Posts:
    127
    Thanks a lot,
    Ill try that.
    though Im not good at shading :p

    --------------------------------
    I read that.
    so seems if I want to have 5 layers to control render order,
    I have to make 5 shaders and 5 materials?
    or can I use "property" to control them?
     
    Last edited: Nov 9, 2011
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This appears to be a bug. I'll try to get it fixed In the next version.

    Cheers,
    Unikron
     
  32. Hao-Cher-Hong

    Hao-Cher-Hong

    Joined:
    Dec 15, 2010
    Posts:
    127
    and I think if I use a sprite in scene
    the mesh instance will leak, (when I save scene Unity will tell me he just clean up the leaked meshes)
    is that right?
    will it cause memory leak?
     
  33. Hao-Cher-Hong

    Hao-Cher-Hong

    Joined:
    Dec 15, 2010
    Posts:
    127
    I found that if I use
    ZTest always | NotEqual
    it renders at the right depth and always in front of 3D objects (I use toon shader for the 3D object)
    and LEqual for block by depth of any objects

    seems I found a great way to solve this? (though I dont know how it actually work XD)
     
  34. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    All of this memory will be cleared when in game, but this memory isn't freed when in the editor. The version we are testing now resolves a lot more of these issues - it is due to clearing the Mesh class and recreating it every time a parameter is changed, but this doesn't happen in game at all, so its fine for use in game.
     
  35. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    As a follow up to this - how many people actually use the name overriding feature in here? My thoughts are to add a bool to force override name, and on every other occurrence, the reason for this bug is there is some ambiguity on whether the name is procedurally generated or not.
     
  36. dead1ock

    dead1ock

    Joined:
    Jan 4, 2011
    Posts:
    31
    Hi,

    I seem to be having an issue with collision detection between 2 polygon-bound sprites.

    I have a Player (spaceship) which has a rigidbody and a polygon collider. I also have asteroids which have a rigidbody, a polygon collider, and has Is Trigger checked.

    When I change the asteroid to TrimmedBox for the asteroid everything works perfectly fine, but i need more precise collision detection.

    Thanks, I really love your product!
     
  37. shaojingkk

    shaojingkk

    Joined:
    Oct 25, 2011
    Posts:
    10
    No commit button in SpriteCollection

    I want to call tk objects in js file, so I want to put tk2d package under "Plugins", but I found when I put tk2d under other folder, not under Asset directly, the commit button in SpriteCollection will missed. How can I fix it? Thanks.

    PS: can not send message in http://www.unikronsoftware.com/2dtoolkit/, it says "Please fill all the fields." But I already filled all the fields
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The files which need to be moved to Plugins are -

    /Plugins
    /Plugins/tk2d

    /Plugins/tk2d/Fonts
    tk2dFont
    tk2dFontData
    tk2dTextMesh

    /Plugins/tk2d/Gui
    tk2dButton

    /Plugins/tk2d/Sprites
    tk2dAnimatedSprite
    tk2dBaseSprite
    tk2dPixelPerfectHelper
    tk2dSprite
    tk2dSpriteAnimation
    tk2dSpriteCollection
    tk2dSpriteCollectionData
    tk2dStaticSpriteBatcher


    /TK2DROOT
    everything else remains here


    This will let you access everything through JS, and the editors should still work. Its slightly annoying that Unity uses different rules to parse editor scripts, depending on where they are located.

    If you need to send a private support request, simply send it to support at unikronsoftware.com


    cheers,
    unikron
     
  39. unikronsoftware

    unikronsoftware

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

    This is a limit of the Unity Physx system - You can only have polygon colliders collide with one another if one of them is convex. If you can set one of your colliders as convex, this should solve your problem directly. Alternatively, you can build the player collider out of multiple boxes and spheres (you will need to do this manually), and this should collide with any polygon collider.

    unikron

     
  40. dead1ock

    dead1ock

    Joined:
    Jan 4, 2011
    Posts:
    31
    Ok thank you, I'll flip my player to convex then as that seems to be the easiest solution.
     
  41. shaojingkk

    shaojingkk

    Joined:
    Oct 25, 2011
    Posts:
    10
    Thanks very much. It worked.
    I think better to document this somewhere, and the Plugin stuff can not move under other folder is a little wired.
     
  42. unikronsoftware

    unikronsoftware

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

    I have added this to the FAQ on the website.

    Cheers,
    Unikron
     
  43. shaojingkk

    shaojingkk

    Joined:
    Oct 25, 2011
    Posts:
    10
    Thanks for your quick reply. Sorry, I got another question, sprite not support anchor point, right? so when scale, it always scale in center. I need to make an hp bar, so want to set anchor point to left.

    PS: I found it's hard to search if my question had be answered. I like flurry's help page, you write your question, it will show some answered question for you to see if that answer solved your problem, if not, you can commit a quest.
     
  44. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Sprite can have custom anchor points. Simply go to the edit page and set it up there. In the viewport, make sure your transform mode is set to pivot mode otherwise it'll always scale from the center.
    Check this page http://www.unikronsoftware.com/2dtoolkit/wiki/pmwiki.php/Main/SpriteCollection for more info.

    I will look into an answers style FAQ system. It will definitely be very useful and reduce my workload quite a bit. Thanks for the suggestion.
     
  45. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    but report: a coworker just told me that he had an issue where adding a fully transparent (empty) png to an animation collection makes Toolkit2d very sad.
     
  46. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    I'd also prefer that changes to a png's name are reflected in the sprite collection drop down.
     
  47. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    I'm not sure what you mean by "the name overriding feature". Do you mean the ability to change the Name in the Sprite Collection Editor? That's not a feature that I use, I prefer to have the actual .png name be the one and only name for an asset across all the editors.
     
  48. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That feature is virtually useless in most cases, except when overriding sprite names sourced from a spritesheet. The default values for names from spritesheets are texturename/01, etc. in most cases it's worth the time going through and labelling them correctly.

    I'm still investigating a fix which won't break backwards compatibility - seeing that it's not working as intended now, that shouldn't be too hard.

    Unikron
     
  49. Bezzy

    Bezzy

    Joined:
    Apr 1, 2009
    Posts:
    75
    Hi!

    Loving 2DToolkit. Has massively improved our workflow with existing assets.

    Just ran into a small problem: setting up colliders. Is there a way to do it to a range of animations, and not just individual ones? Or to stop the animation system overriding the standard collider?
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Colliders are set up per sprite, not per animation. You can batch this by setting up Defaults in the sprite collection inspector. This has to be done before import, and can't be applied after the collection has been created. A new batch editor is in the pipeline but it's low priority compared to other new features.

    I'm not sure I've answered your question though - if I haven't just post a reply with more details.

    Cheers,
    Unikron