Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

SM2 - 2D made easy and efficient!

Discussion in 'iOS and tvOS' started by Brady, Nov 4, 2009.

  1. helmishariff

    helmishariff

    Joined:
    Nov 29, 2007
    Posts:
    107
  2. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Yes, Stop() will stop it, but if you want it to naturally stop on its own without looking, just be sure not to set the "loop cycles" member to -1 or to a positive value. If it is set to 0, it will play once and stop. If it is set to a positive value, it will repeat itself that number of times (if it is set to 1, it will place the initial time, then repeat 1 additional time). -1 loops infinitely (unless the animation is changed, Paus()ed, or Stop()ped).
     
  3. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    Give me a look... :eek:
     
  4. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
  5. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    I'm having some issues with texture compression and texture memory.

    1. Some of my sprite atlases (generated by SM2) are not square (eg. 1024 x 512, 256x512) and so they aren't being compressed. From what I've read in the docs, it sounds like in order for compression to work, textures need to be power of 2 AND square. How can I get compression on these non-square textures?

    2. I thought that only the sprite atlas should be exported and used in the game (and therefore take up memory). But according to my editor.log, the sprite atlas *and* the source texture are in the build.

    Used Assets, sorted by uncompressed size:
    2.7 mb 8.6% Assets/Sprite Atlases/SpriteMat L-A-G4.png

    ..a little further down in the log...

    1.3 mb 4.3% Assets/Textures/Level/L-A-S09.png
    1.3 mb 4.3% Assets/Textures/Level/L-A-S08.png



    L-A-S08.png and L-A-S09.png are the textures that are on SpriteMat L-A-G4.png so it seems that the source textures are also being exported as part of the scene and taking up memory. Why is this?
     
  6. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    1. Currently, there isn't a way to force square textures because PackTextures() doesn't support it. However, there are ways it can be worked around (with lots of effort) which I plan to implement shortly. This has so far been somewhat low priority due to what is required to implement and the fact that 99% of the time sprite will look awful with PVRTC compression.

    2. This is addressed in the documentation. Before your final build, currently you need to just drag your source textures outside your assets folder, then just drag them back afterward. I'm still looking for a way to automate it so that they aren't included with the build, but at the moment it doesn't appear that Unity supports any way to tell it that certain objects which are referenced should not be included, nor is there any kind of "PreprocessBuildPlayer". So for now, just dragging out, build, then dragging back in will work just fine.
     
  7. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    I'm building my level backgrounds out of several 512x512 alpha .png textures. So I have 4 512 textures per sprite atlas which makes them 1024. With compression ON, there are some artifacts, nothing awful but looks bad to me. With compression OFF (RGBA 16bit), the atlas size gets pretty huge - the Inspector says "Memory: 2.7mb", I don't know how accurate that is.

    Anyway, is there a way to get good looking large textures without compression that don't hog all the memory?

    BTW, to get around the non-square texture problem, I added an animation to the Packed Sprite with 1 frame and assigned a different 512 texture to it (hack!). So now the sprite atlas has 3 textures instead of 2 and is now square.

    So between moving out the texture folders during build (bit of a pain BTW) and getting compression going on that remaining atlas, my texture memory went from ~31mb to 7mb!
     
  8. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    I find that PVRTC compression artifacts are less visible on a larger texture that has been scaled down. So if you have a character sprite which is roughly 128x128 on screen, make its texture 256x256 and the artifacting should be far less visible, and the files still substantially smaller than an uncompressed 128x128. Of course this requires that you author your textures at a high resolution.

    Almost all of the art in OMG Pirates! uses PVRTC, the character art was all authored at 512x512, scaled down on import to 256x256, and then scaled down further in-engine by being rendered on small-ish objects. It worked out pretty well despite the heavy-outlined style of the art.
     
  9. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    No, I'm not aware of another way to save memory, as I believe any uncompressed textures will be a set size based on their dimensions.

    That's a decent hack for the moment, but I intend to implement the option to force the generated textures to be square soon. I have an idea how I'll do it.

    BTW, with regard to the issue of keeping source textures out of a final build, please vote for this item on the official Unity wish list:
    http://feedback.unity3d.com/pages/15792-unity/suggestions/378721-editor-preprocessbuildplayer

    This would allow the placing of source textures into a standard folder, and then the PreprocessBuildPlayer script would automatically sequester the files prior to build, then a PostprocessBuildPlayer would replace them upon completion.
     
  10. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
  11. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    It's just saying that there aren't any free download slots available at the moment. Keep trying and one will open up.
     
  12. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    UPDATE: I can now confirm that forcing square atlases will be supported in the next release.

    I also plan to include an option to do your project build in a way that will take care of moving your source textures out of your assets folder automatically prior to build, and move them back when the build is completed, thus freeing you from having to do this manually. You will just have to keep your source textures under a specific folder so that they can all be moved out and back together. They can be organized under this folder in sub folders in any way you choose, but they must be somewhere under the specific folder - which is best practice anyway.
     
  13. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    Thanks,I downloaded...

    But...

    Order Now - Single User (single-seat)
    $75 USD

    Order Now - Studio License (unlimited seats for your studio)
    $275 USD

    I want free.... :p
     
  14. dawvee

    dawvee

    Joined:
    Nov 12, 2008
    Posts:
    276
    Hi Brady, SM2 looks great! I had one question, about the anchor point used for the sprites. I haven't read all the replies here, but I did a quick search and turned up nothing.

    My question is, does SM2 just use an enumeration for the anchor values? It would be awesome if it could use a vector instead, so you could Lerp the anchor point. That would be great for scaling and rotating, as a flexible, animatable anchor point can really be useful for getting things to look just right.

    Where I'm coming from is that I've recently been working with Cocos2D, which uses a CGPoint from (0, 0) to (1, 1) as the sprite's anchor, and I found it invaluable being able to animate that property when scaling and rotating sprites.
     
  15. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    It currently does not allow non-enumerated per-frame anchor points, however that is definitely a high priority item on my To Do list. So barring some kind of unforeseen reason why it couldn't be implemented anytime soon (which I can't imagine there being any), look for it within the next few releases.

    BTW, please PM me, I'm interested it discussing the "lerping" of the anchor point with you.
     
  16. dawvee

    dawvee

    Joined:
    Nov 12, 2008
    Posts:
    276
    Great! After I looked over the features and videos on the site you pretty much had a sale anyway, but the anchor point thing was just the one little thing that jumped out.

    PM sent, btw.
     
  17. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I'm really liking SM2 but I do have a minor complaint. I am using it to build a tabbed interface. At any given time, no more than 1/5 of the content is set to active. All inactive packedSprite objects do not get included in the texture atlas. Whenever I need to modify the atlas, I need to set every game object in my game to active all at the same time, bake the texture atlas, and then re-hide a lot of content.

    I would really like to see some feature that allows a texture to always be included, regardless of it being inactive. Barring that, perhaps you could add something that saves active flag settings, unhides all objects, bakes the atlas, and then reapplies the active settings.

    Oh yeah, and it would also be nice if the generated texture atlas retained import settings. I'm tired of turning off mips on my pixel perfect texture atlas every time I generate.
     
  18. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I'll look into preserving import settings (it is technically a new texture every time, so I'll have to check the settings of the existing atlas first, if any).

    On the disabled sprite issue, that is currently a limitation created by the fact that FindObjectsOfType does not return disabled GOs. But I'm working on a way to do it that hopefully doesn't even require the sprites to be in the current scene.
     
  19. dawvee

    dawvee

    Joined:
    Nov 12, 2008
    Posts:
    276
    Brady, my hat is off to your for SM2. I've been playing around with it today and having an absolute blast. So far I've been abusing it horribly, simultaneously drawing thousands of multi-layered transparent sprites in a single draw call and seeing if it nukes my iPod Touch, but every single time it's run brilliantly! And here I thought I was going to miss GL_POINTS. 8)
     
  20. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Haha! Great! I'm glad you're enjoying it. :)
     
  21. jbury

    jbury

    Joined:
    Nov 7, 2008
    Posts:
    87
    I noticed you added some new videos to your site and finally caved and got myself a copy of SM2 - thanks Brady! :)

    I was using SM1 for just having sprite bullets and realised with SM2 I could probably have those bullets with an animated texture on which would look a lot better

    Just wanted to say thanks :)
     
  22. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Thank you! I'm glad you're enjoying it. :)
     
  23. jbury

    jbury

    Joined:
    Nov 7, 2008
    Posts:
    87
    Hey Brady, sorry for the hassle (its the weekend so I decided to start trying to switch my Spritemanager stuff over to Spritemanager2)

    I'm having some trouble as the Spritemanager2 stuff seems to be clashing with GUIManager (I'm currently using this for the UI stuff for my iphone game)

    I'm getting a lot of errors such as:
    Assets/Editor/SpriteTimelineEditor.cs(518,33): error CS0117: `GUI' does not contain a definition for `Label'

    Assets/Editor/SpriteTimelineEditor.cs(510,25): error CS0117: `GUI' does not contain a definition for `contentColor'

    I know there is a "GUI" file in the plugins folder that comes from GUIManager so I'm guessing its making something explode.

    I know you can't really resolve problems from clashes with other peoples scripts, but I wasn't having this happen with Spritemanager 1 - is this something fixable or will I need to pick between using one or the other?
     
  24. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I would suggest dropping the GUIManager and just sticking with SM2. I'm currently using SM2 solely for the UI on my current project and I can tell you it's fairly simple to make buttons with minimal code in SM2.

    I was actually considering sharing my SM2 button class with everyone. When I get back to my Mac I'll take a look at the code and make sure it doesn't expose any of the SM2 code.
     
  25. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Would recommend the same.
    You can't have sprite manager and sprite manager 2 in a project, that will not work. And GUIManager / SpriteUI will only work with sprite manager.
     
  26. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    It sounds like GUIManager isn't clashing with SM2, per se, but rather with Unity GUI. The lines in those error messages are calls to Unity GUI and it would appear that GUIManager has classes by the same name that are interfering. You could try editing SpriteTimelineEditor.cs to fully qualify "GUI" by doing a search and replace that adds "UnityEngine." to the beginning of all "GUI" calls. That way the compiler knows that in those cases, "GUI" refers to Unity GUI and not some other class called "GUI".

    I've never used GUIManager, but if it does include a class called "GUI", I'd really recommend changing that since it's not a good idea to have classes named the same thing as Unity classes as you'll get precisely these kinds of errors eventually, and the only way to resolve them is to fully qualify the class names.

    EDIT: I'm not sure what I was thinking... those error messages definitely do seem to be the result of what I described above, however, SM2 will class with SM in other ways because SM1 (the latest version) already has its own Sprite class which is different from SM2's Sprite class, and so these two will clash. I suppose you could refactor/rename one of the two Sprite classes to get around this.
     
  27. jbury

    jbury

    Joined:
    Nov 7, 2008
    Posts:
    87
    Thanks a lot for the speedy help guys

    I'd like to keep using GUIManager if possible, as I'm terrible at scripting and its all setup and working in my game how I need it

    So my two options are to stick with SM1 (which is in and working) but not be able to do some of the things I want, or try the renaming thing you mentioned to get SM2 working

    I'd like to get SM2 working so I guess thats the route I'll need to go - thanks again for the help :)

    EDIT: Yep, renaming the GUI file in plugins to something else (I named it GMGUI) and changing its classname seems to fix all ills so they play nicely together :)
     
  28. jbury

    jbury

    Joined:
    Nov 7, 2008
    Posts:
    87
    I must have worded it wrong as that was never my intention - my game currently uses SM1, I would like to remove its use of SM1 and convert everything across to SM2 instead :)

    (but also using GUIManager)
     
  29. u3dclt

    u3dclt

    Joined:
    Aug 10, 2009
    Posts:
    30
    I'm trying to get SM2 GUI buttons to play animation clips (both 3d imported animations, and SM2 - PackedSprite clips)

    The 3D clip can be dragged from the Project view onto the button to associate the two.
    I don't see a way to do the same for the SM2 PackedSprite animation. The SM2 clip doesn't show up in the same Project view list.

    I'm using JS code for the movements, etc.

    I've been able to get other SM2 buttons to work with JS and Raycast but not animation clips.
     
  30. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    u3dclt, I'm not 100% sure what you're trying to do here so let me ask a couple of questions to see if I understand you.

    1) Is the problem that you are unable to associate 3D animation clips with a GameObject that contains a PackedSprite component? And if so, is the animation one that was created in a 3D modeling package, or are you referring to something created using Unity 2.6's animation editor?

    2) Or is the problem that you are not able to drag a sprite animation clip to another GameObject?
     
  31. twomack33

    twomack33

    Joined:
    May 14, 2009
    Posts:
    10
    Mattimus I would really like to see your SM2 Button class, if you are still offering :)
     
  32. u3dclt

    u3dclt

    Joined:
    Aug 10, 2009
    Posts:
    30

    Brady wrote:


    1) Is the problem that you are unable to associate 3D animation clips with a GameObject that contains a PackedSprite component? And if so, is the animation one that was created in a 3D modeling package, or are you referring to something created using Unity 2.6's animation editor?

    Yes, I'm trying to use an SM2 button to play a 3D animation (imported from a 3D modeling package), and/or also play an SM2 PackedSprite animation.

    I was able to use SM2 buttons (with UnityJS) for other GUI activity but not for animation yet. I know it's all in the code. Just looking for some guidance.
     
  33. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    First, the animation has to have been set up for the sprite in question. You can use the timeline editor to do this. Then, to cause the animation to play from code, call PlayAnim() passing it the argument of either the index of the animation, the name of the animation, or a reference to the animation. For all the details, see the sample script that comes with SM2, or the JS version that is attached to one of my posts on page 6 of this thread (the JS version will be packaged with SM2 in future releases).

    Let me know if you have any more questions.
     
  34. u3dclt

    u3dclt

    Joined:
    Aug 10, 2009
    Posts:
    30
    Working!

    I figured out what I did wrong.

    In the Script Component (in the Inspector window)
    I hadn't declared my PackedSprite animation in the target area. It works now!

    So that's where you can drag and drop your PackedSprite animation from your Hierarchy window. Or select it from the side pulldown menu.

    Thanks Brady!
     
  35. u3dclt

    u3dclt

    Joined:
    Aug 10, 2009
    Posts:
    30
    Correction, I got the PackedSprite animation working but not the 3D animation.
     
  36. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I'm not sure about the 3d animation, but that shouldn't be specific to SM2.
     
  37. u3dclt

    u3dclt

    Joined:
    Aug 10, 2009
    Posts:
    30
    No it's definitely not tied to SM2. Most likely a problem with my variable declaration for the imported 3d animation.
     
  38. wh00kah

    wh00kah

    Joined:
    Jan 29, 2009
    Posts:
    11
    Hey Brady. This SM2 looks fantastic! I've gone through the tutorial videos as a "demo" and it's right up my alley, as my partner has just finished up art on a 2D puzzler right now.

    Two questions:

    1) Assuming "early adopters" get access to the SM2 first official release free, right?

    2) You have some other cool middleware (EZ Game Saver) on offer as well. Any chance of a bundle (or holiday discount)? A bundle would be cool *hint-hint* :wink:

    Regardless, I'll definitely be getting one or both soon enough.
     
  39. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    wh00kah:

    1) Yes, you will receive free upgrades until a 2.0 or SM3 is released (no plans for that at the moment, considering 1.0 is still to come :)).

    2) Yes, if you add SM2 to your cart and proceed to check out, you should see on the right an offer to add EZ Game Saver for $25 off as a bundle.

    Thanks for your interest!
     
  40. tau

    tau

    Joined:
    Dec 15, 2008
    Posts:
    113
    Brady, just got the RC5 of the SM2 and wanted to submit a bug report :).

    I noticed 2 things:
    1) I cannot make a pixel perfect PackedSprite sprite: as soon as I turn the option on, the sprite disappears from the views; if I uncheck it and set the dimensions, it shows up, so I assume it's not a problem on my side (I do have the ortho camera setup).

    2) This one is minor but rather annoying if using Visual Studio as the editor and compiler. I noticed that you declared "enums" in the SpriteBase as "static"; I assume that your background is in C/C++? ;) It gives a compiler error in Visual Studio/SharpDevelop as enum definition cannot be static in C# (it's a value type declaration as opposed in C++ where it's a variable declaration), however, the mono compiler that comes with Unity simply eats it, I assume it has more relaxed check settings. If you remove "static", those enums will be available outside the class as intended. You also can declare those enums outside any class, I usually have a dedicated file for enums, makes editing easier.



    Thanks!
     
  41. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    1) just enter the play mode once and it should appear normally
     
  42. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Thanks for the feedback.

    1) I'm not sure about this one. Try checking the option, pressing play real quick then stopping again and see if it shows up correctly. Other than that (which happens sometimes due to how/when Unity updates things), I haven't seen that behavior. If the above doesn't work and there are additional steps to reproduce this, please let me know.

    2) You guessed correctly, my background is C/C++. :) I've made the suggested changes in my internal version for the next release. Thanks!
     
  43. tau

    tau

    Joined:
    Dec 15, 2008
    Posts:
    113
    I did a lot of C++ coding before switching to C#, looking at your code was quite a "deja vu" :)

    Found why the sprite was dissapearing, it's throwing exception:
    Code (csharp):
    1.  
    2. NullReferenceException
    3. SpriteBase.CalcSize ()   (at Assets\Sprite Scripts\Support\SpriteBase.cs:1372)
    4. PackedSprite.StepAnim (Single time)   (at Assets\Sprite Scripts\PackedSprite.cs:288)
    5. PackedSprite.PlayAnim (.UVAnimation anim)   (at Assets\Sprite Scripts\PackedSprite.cs:403)
    6. PackedSprite.PlayAnim (Int32 index)   (at Assets\Sprite Scripts\PackedSprite.cs:422)
    7.  
    That line of code has the reference to the current camera, and I did not set the current camera on that sprite, I use a non-default camera. after calling SetCamera() on the sprite object, the sprite shows on but only when I run the game.

    Note, that with PixelPerfect=off, it was finding the camera and not throwing the exception!

    I wonder if by default the sprite can scan the scene for cameras and pick the first one if the curCamera is null? Also, will it be possible to show the pixel perfect sprite at design time?..

    Update:

    I noticed that the PixelPerfect sprites have a little bit of distortion (do not look very crispy). I compared it to the same texture rendered via GUITexture, the visual size is the same, but PackedSprite shows visual distortion. I played a little bit with the CalcSize() but could not get it right. I wonder if it's a combination of settings in the camera, or it's a known issue? I can get better results by guessing a good sprite size with PixelPerfect=off.

    Another thought, I did not look at how the UV is calculated or when, but it looks like the UV is calculated before the resizing/size calculation, thus resulting in distortion when applied during rendering.
     
  44. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    This should not be an issue in the next release as you may now select which camera to use for the size calculation in-editor. Until then, the sprite will use the default camera.

    Regarding the distortion you refer to, the UVs are calculated when the atlas is built - it is merely finding the locations of the desired pixels on the atlas. This must necessarily be done before calculating size, and indeed, the size is based on this. I believe what little remaining distortion you may be seeing could be due either to mipmapping or texture filtering. Try disabling mip maps and try different filtering or no filtering. GUITextures do not suffer from this because of the way they are rendered, but are not batched and incur a draw call per GUITexture.
     
  45. tau

    tau

    Joined:
    Dec 15, 2008
    Posts:
    113
    Brady, you pointed me in the right direction, setting the atlas texture Filter Mode to "Point" did the trick and the sprite looks very sharp (I think this could be a nice addition to SM2 FAQ), I kinda forgot about texture filtering, my bad :oops:

    The change for the camera would be really helpful!

    BTW, I'm still experiencing the sprite image disappearing from views (the sprite's mesh becomes invisible or removed) when the PixelPerfect=on at design time, it's only visible when the game is running in the editor; with the PixelPerfect=off I can see the sprite at design time in all views. Hint: could it be that the size for PixelPerfect=on does not have a chance to be calculated in the editor, and for PixelPerfect=off it already has the size thus it shows up?

    Thank you for help and patience! Keep up the excellent job!
     
  46. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    If the sprite in question is using a camera other than the main camera, then yes, it will not appear correctly in the current version at design time (will be fixed in the next release), but it should still appear at some size, though you may not see it depending on the settings of the main camera, which could be why it is not visible to you. But if it uses the main camera and the main camera is orthographic, then at most, you should only have to press play once briefly and it should appear in edit mode from then on.

    Let me know if I'm misunderstanding your setup.
     
  47. Peter D

    Peter D

    Joined:
    May 3, 2009
    Posts:
    106
    Just joined the sprite manager 2 owners club :D

    Quick question. How do I go about downloading the release candidates later. Currently I have RC5 but, do you send out download links to customers as the release candidates are created or is there some spot to download them using the serial number or something?

    Cheers.
     
  48. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    There is a place to download them using your order number, however, silly eSellerate limits the number of times customers can re-download from that source without me resetting it periodically per-customer. So I'm looking at just having an encrypted download linked on the website that unlocks using your serial number.
     
  49. tau

    tau

    Joined:
    Dec 15, 2008
    Posts:
    113
    I re-arranged my setup to use main camera, and it does appear in edit mode, but the mesh size is changing to a random value every time I stop the game.
    Seems like it recalculating the size in editor, but confused about the ortho size.

    Let's see if the next release fixes it, it just makes difficult to place the sprites in editor right now: have to hit play, visually note the sprite size/position and re-arrange sprites.

    BTW, the demo package exhibits same behavior on the "packed, non-uniform, pixel-perfect, anchored" sprite, but it shows from time to time, not always.

    If I dont find an issue on my side in a day, I'll send you a test project.
     
  50. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Yes, please do. That is very strange behavior you are describing, and I have not seen it occur at all with the demo project and haven't received any reports of this from anyone else, so I'm very interested to see what might be going on in your case. Thanks!