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

Sprite Factory - Sprite Animation System

Discussion in 'Assets and Asset Store' started by guavaman, Jul 28, 2013.

  1. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Thanks for the input. When I get back home tonight I'll dig deeper. The only thing that really makes this even stranger is that when this isn't working, the spriteMaterial is null in the Awake method of the component that has the reference to the sprite. And that just seems impossible. I suspect you're right that it's some side-effect of something else, but I'm just not seeing it yet. Hopefully, more debug will help narrow it down.
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    This could be possible if the component that has the reference to the Sprite has initialized before the SpriteFactory.Sprite component itself. Unity makes no promise about order of initialization of components unless you set the Script Execution Order explicitly. (The order you see them in the inspector does not indicate order of initialization.) If your side component runs Awake first before Sprite runs Awake, the spriteMaterial would be null because the Sprite hasn't set it up by the time you call it.

    You could either set the Script Execution Order of SpriteFactory.Sprite to a value less than 0 so it initializes first or run your side component initialization in Start instead of Awake.
     
    Last edited: Aug 5, 2015
  3. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I figured out the issue. I made a bad choice and had a call to deactivate the main component that had the reference to the SpriteFactory.Sprite within the Awake of that component. Thus, since the sprite had not yet gotten its Awake called, it never got called because it was deactivated. I moved the call to the Start method and it's working now. Thanks for the help.
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Ok, good!
     
  5. FractalCore

    FractalCore

    Joined:
    May 15, 2009
    Posts:
    151
    I read here, a year ago you mentioned making Playmaker actions. I've just started using Sprite Factory, and some Playmaker actions would be great.

    I started using looping sprite animations and everything seemed fine, then when I went to trigger a play once animation, it only worked one time. Then further triggerings didn't start it from the start again. I assumed every time I deactivated then activated the sprite object (using Playmaker) it would start again. But it doesn't seem to.

    So all this is done without coding which is why I could really use Playmaker actions for starting and stopping etc. Just the basics.
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Play once animations are by definition designed to play once. Once the animation is finished, calling Play again will make it play again from the start. If the animation hasn't finished, you must pass a Boolean value to tell it to replay from start. If you've set the loop mode to Clamp, it won't ever be considered "finished" so replaying it without specifying replay from start = true will make it look like it isn't doing anything.

    I have a set of Playmaker actions, but it doesn't cover absolutely everything (like SpriteMaterial). I will post it here on late tomorrow as I do not have access to the files at present.
     
  7. FractalCore

    FractalCore

    Joined:
    May 15, 2009
    Posts:
    151
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    @FractalCore Here are the PM Actions.

    Re: Sid's message in the PM forums. I created these actions for him. He's been using them for a long time now. Thanks for pointing that out though.
     

    Attached Files:

  9. darthbobr

    darthbobr

    Joined:
    Jul 2, 2014
    Posts:
    6
    I took a look on the documentation, however can't figure out 2 questions:
    1. Is there a way to create master-sprites with code? For instance - I have a lot of characters, I have a set of sprites for each character, information on which sprite which event should occur, etc. So I'd like to generate all animations and not create them in editor. Is that possible in Sprite Factory?
    2. Is there a support for layers like in standard Unity? For example I'd like to make my animated character grow bigger/lesser periodically on some sort of event. In standard Unity I could do that by adding one more animation layer. Is this somehow managed in Sprite Factory?
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    No it is not. You have to use the Sprite Factory editor to create all your Master Sprites and Sprite Groups.

    No. A Sprite Layer implies you are animating multiple discreet sprites in sync as a unit (upper body, lower body, head, etc). The Sprite Factory animation system is designed for animating a single bitmap sprite at a time. If you need to animate multiple sprites together, you need to create them as separate sprites and manage their animation manually using scripting.
     
  11. darthbobr

    darthbobr

    Joined:
    Jul 2, 2014
    Posts:
    6
    Thanks for the answers.
    Ok, there's no sprite layers, however I've not understood is it possible to achieve with Sprite Factory what I need.
    To make it clear - I have an animated sprite building (a single bitmap for each frame). When the user clicks on it - I want it to start pulsing and glowing. In other words, I need to apply additional "curves" to that animation on the user's click. Is that possible?
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Not directly using Sprite Factory's animation. It plays back at the frame rate you set in the editor. You could however implement this by making a script that changes the animation playback rate based on user actions or by changing the current animation frame index if needed:

    http://guavaman.com/projects/spritefactory/docs/pages/classes/Sprite-playbackSpeed.html
    http://guavaman.com/projects/spritefactory/docs/pages/classes/Sprite-GetAnimationSpeed.html
    http://guavaman.com/projects/spritefactory/docs/pages/classes/Sprite-SetAnimationSpeed.html
    http://guavaman.com/projects/spritefactory/docs/pages/classes/Sprite-PlayAtFrame.html
    http://guavaman.com/projects/spritefactory/docs/pages/classes/Sprite-currentFrameIndex.html
     
  13. darthbobr

    darthbobr

    Joined:
    Jul 2, 2014
    Posts:
    6
    Hi! I'm using the full version of Sprite Factory 1.116 (under Unity 5.2.0f3) and I've got a following issue: I have a couple of sprites with animations in my scene and in runtime some sprites are working fine, and the others are drawn twice. When I play an animation, only one copy of the sprite is actually animated, the other plays default animation. I've looked on the object that's drawn twice and it has 4 children SpritePlanes - 2 are active and 2 disabled. In editor - he had no children at all, so I guess this SpritePlanes are created by SpriteFactory in runtime. When I look on the properties of the sprite that works fine - he has no children at all. I've checked the Sprite properties - they seems to be the same for both sprites. Am I missing smth.?
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    @darthbobr

    Never heard of or seen anything like this. Is your project small enough to send via Dropbox or something? I will PM you the email address.
     
  15. darthbobr

    darthbobr

    Joined:
    Jul 2, 2014
    Posts:
    6
    No, my project is quite big and consists of 4 parts - riak database, lobby, server and client. And it doesn't have any hosting yet. I'll try to make a video showing what's wrong and send it to you to make it clear.
     
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Can you reproduce the issue in a new (smaller) project?
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Update: The issue has been resolved in 1.118 which will be live on the asset store in a 5-10 days.
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Spritre Factory 1.118 is live on the Unity Asset Store.

    1.118
    Changes:
    - Sprites can now be duplicated in the scene at runtime and colliders, locators, and sprite planes will all behave correctly.

    Bug Fixes:
    - Setting animation speed to 0 now stops all animation.

    1.117
    Bug Fixes:
    - Fixed issue where the last frame of an animation was intermittently drawn when frame rate is low.
     
    Last edited: Oct 27, 2015
  19. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    This link in your message points to Rewired rather than Sprite Factory
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Whoops! Fixed.
     
  21. billy-kahong-chan

    billy-kahong-chan

    Joined:
    May 23, 2014
    Posts:
    9
    That's will be great if I can scale or rotate the sprite image in the editor. Can I do that ?
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    No you can't. Sprite Factory isn't intended to be a bitmap editor or replace functionality of Photoshop. It is expected that your art is finalized before you import it. Sprites can be scaled in the world after they are created into 3D object, but they cannot be scaled in the editor.
     
  23. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Hi,

    I'm currently making a 2.5D project and was using mecanim for sprite animations but it seemed too overkill (and unncesarily complex) for my characters animation and, at the same time, I didn't have enough control over them.

    So I've been trying the trial version of Sprite Factory and wow... I guess you have spent your fair share of time animating or even analyzing in emulators how Capcom/SNK do their stuff because it covers all the necessary areas for 2D sprite animation: Frame holds, offsets, locators, hitboxes (in the form of colliders), playing at a determined frame... Great work!

    Right know I have a few doubts about finally jump ahead and change my current implementation and I'll have to do further testing, mainly related to compatibility with other assets.

    - Compatibility with 2DxFX (Link): In the description it talks about SPRITE RENDERER. Since Sprite Factory uses meshes, I guess it is not compatible?

    - Compatibility with Chronos (Link): I guess that Sprite Factory uses references to Time in it's code. There's a guide in Chronos website to migrate from standard Time to Chronos: http://ludiq.io/chronos/migration . Should I change your source code to support chronos?

    Thanks in advance
     
  24. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Just revised your source code and according to Chronos migration guide, the only thing that should be changed are 3 calls to Time.deltaTime to became Timeline.deltaTime. Is there any way to expose a variable to define if I use Time.deltaTime or another value?
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Thanks! I do have a 3D graphics and animation background.

    Sprite Factory uses Mesh Renderer, yes. Sprite Renderer is used by Unity's 2D system they introduced in 4.3. Sprite Factory does not use this system. If 2DxFX requires Sprite Renderer to function, it won't be compatible.

    That would be the only way, yes.
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    I could but I wouldn't know how or where to expose this. As a global static variable? As a field in each Sprite? I'm thinking some kind of static helper class needs to be created to hold this and so Sprite Factory can detect its been overridden. You would also need to update/set this delta time each frame before Sprite Factory updated, which would mean you'd need to set script execution order on Chronos or your helper class very low.

    I also see other problems. The Chronos link shows that you have to change all kinds of settings with relation to Rigidbodies. These are used in hit boxes/hurt boxes and optionally throughout the collision system.
     
    Last edited: Mar 18, 2016
  27. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Yes, I believe it's a field in each sprite. Each gameobject have it's timeline (so 1 object can be at a determined speed and another at other speed) http://ludiq.io/chronos/documentation#Timeline.deltaTime

    I can live without the sprite effects but slowing down time / pausing is needed and it looks sooo close and sooo far at the same time... :p

    I've noticed that the asset actually uses a DLL instead of C# clases... should I extract the source code from "source" and recompile it? I've never done something similar. Also I believe that if I reference Chronos' Timeline class I'll get lots of errors since it's an external class... any suggestion or idea? Can I just copy the project folders into my Assets folder?
     
  28. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    The only instance of Time related modifications are located here in Sprite.cs (lines 17 and 38 of this excerpt)

    ---- CODE REDACTED ----

    Makes sense since it's the point where a sprite is animated. If "Time.deltaTime" could be changed into some kind of parameter per-sprite it would work. IE: Choose between "Automatic mode" which would use Time.deltaTime as is it usual or "Custom mode" which could accept a float from a class or gameobject. That class would have the updated value of Timeline.deltaTime and would be executed with a high priority (IE: -100 in script execution order) so the value would be ready for the sprite update...
     
    Last edited: Mar 18, 2016
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Please do not post source code here. Sprite Factory's source code is only available to purchasers.
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    You cannot just extract the DLL's into Unity and have it compile it. Everything will break. The only way to update Sprite Factory is to rebuild the DLLs from Visual Studio.
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    If it has to be per-sprite and not global, there's no alternative but to expose a field and have some other script feed the value into it every frame. You would have to have some kind of ChronosSpriteHelper component that you add to every Sprite, then have that component change the value of the field on a low ScriptExecutionOrder.
     
  32. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Yeah I was thinking in that direction. I tried to compile it before but without success, I'll give it a more in-depth look this week.

    Sorry about the code, in the future if I need assistance with your code I'll write a PM.

    Is the asset tested on consoles, mobile?... I wouldn't like to move my work to Sprite Factory only to discover that it's only for PC (altought for what I've read it's multiplatform and in the code I haven't seen anything too exotic for multiplatform)
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    There is no platform-specific code in Sprite Factory. It has been a very long time since it was tested on iOS or Android, but unless there have been new bugs introduced since then, it should work. It has never been tested on any consoles to my knowledge.

    I will look into exposing the deltaTime field in the coming days.
     
  34. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Thanks a lot! I'm also using Rewired and it's fantastic so your logo and your name have a deserved place in the credits of my game (and a nice review too ;) )
     
    guavaman likes this.
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    You know, it just struck me as I was looking through the code that you can already do this very easily without changing Sprite Factory by simply setting the Sprite.playbackSpeed property.

    All you'd have to do is set that based on your Chronos deltaTime something like this:
    sprite.playbackSpeed = Timeline.deltaTime > 0 ? Time.deltaTime / Timeline.deltaTime * baseSpeed : 0;

    This is cleaner, more general purpose, and makes a lot more sense than adding some kind of customDeltaTime property that has no other use but for this. Plus I think messing with deltaTime might cause problems with SpriteFactory's frame timing system that tries to keep a consistent playback frame rate regardless of the actual current update rate.

    Even better, if Chronos exposes some kind of overall Time Speed/Scale parameter instead, just use that instead of calculating it.
     
    Last edited: Mar 19, 2016
    SVC-Games likes this.
  36. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Success!! I've made a simple class in my Timekeeper gameobject (which manages all the different clocks of chronos) to expose the timeScale of any individual clock in action. Then, in my sprite Update, I simply do sprite.playbackSpeed = timekeeper.GiveMeTheTimeScale("Desired clock") and BAM!

    So excited with this you can't believe it. Mecanim was a bit of a headache for animation + moving colliders + locators and Sprite Factory is great for that exact things.

    Just 2 suggestions if you plan on updating Sprite Factory:
    - The ability to select multiple frames of an animation to edit things like Frame Hold. Is kind of a pain to go frame by frame changing it when an animation use a similar framehold for every frame. I guess I could have the same efect having a framehold of 1 (default) and changing the FPS but as soon as you put some in-betweens it may mean to change the whole animation.
    - When dragging frames I believe it arranges them by name, but when the name have a number it doesnt follow the proper order. IE: When dragging something like "walking7, walking8, walking9, walking10, walking11, walking12" it reorders it as "walking10, walking11, walking12, walking7, walking8, walking9". Again, it's a minor gripe that can be easily avoided by calling the files something like "walking009, walking010, etc".

    Thanks a lot for your support and understanding :D
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Good! Glad this was easily solved without making changes to the system.

    Sprite Factory is feature complete at this point. I have no plans to make any additions to it, only bug fixes should anything break in a future version of Unity.

    That would require a huge number of changes. The list box system I created does not support multiple selection and neither do any of the controls on any page.

    Actually, that is the proper order. Alphabetical order. Frame number padding is almost always necessary when working with frame sequences in most programs including After Effects, Premiere, etc... at least it used to be last time I used these programs (which was admittedly many years ago). This could be changed for convenience however, although I don't think it would be worth releasing a new version just to change this.
     
    Last edited: Mar 19, 2016
    SVC-Games likes this.
  38. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Yes, as I said, they're minor grips (more probably bad habits of mine). If it ain't broke... ;)

    Again, thanks a lot
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    NP!
     
  40. Alunze

    Alunze

    Joined:
    Jun 2, 2013
    Posts:
    11
    Hello!
    Just checked the trial version, looks very promising!

    I did some tests and something I noticed is that the generated atlas texture is of lower quality (i.e. has some jpeg-like visual artifacts) than the individual source textures. Is this intentional (so I can expect the full version to reflect the source textures) or maybe there is something wrong with my settings? The source textures appear correctly in the editor and inspector indeed.

    This is how it looks in my system. Left is the source texture, right is how it looks in the generated atlas.

    In any case, pretty impressive work. Thumbs up!
     

    Attached Files:

  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Do you have compress textures enabled: http://guavaman.com/projects/spritefactory/docs/pages/UsingTheEditor.html#EditorProperties

    Sprite Factory does not do any kind of compression on its own unless you set the Resolution Target to a smaller size. The only other possibility is the shader being used on the material. Change the default material to a new Material that uses Unity's default Sprite shader and it will probably look correct. (Also in the same editor settings window.)
     
  42. Alunze

    Alunze

    Joined:
    Jun 2, 2013
    Posts:
    11
    Hello! That's what I call a fast answer :)

    That's what's puzzling me, I'm not setting the atlas to use compression nor reduce the resolution, the parameters are mostly default, except from setting the default filter mode to 'Point' for the pixellated look.

    The material used for rendering doesn't seem to have anything to do with the problem, as the artifacts are in the atlas itself. In the attached image you can see the source texture compared with the generated atlas file.

    Just in case it helps, I'm using .png files, and my Unity version is 5.3.4f1. Any other info I can prove, just ask.

    Thanks a bunch!
     

    Attached Files:

  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    @Alunze

    I see what you're looking at. That's a watermark because you're using the trial version. It's very hard to make out because of the size. Add a 512x512 solid black PNG and you'll see it clearly.
     
  44. Alunze

    Alunze

    Joined:
    Jun 2, 2013
    Posts:
    11
    Ok, makes perfect sense! Thanks for clarifying!
     
  45. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Wow, talk about a lucky coincidence! I was trying a shader to change palette colors on my sprites while away from home and was having weird artifacts when replacing colors. That watermark explains what was happening. Since I'm using the trial version on my laptop (I'm not sure how Unity handles the whole "one license per seat" thing and I don't want to lose all my bought assets for opening my project on my laptop) I guess I should try again at home :D
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Unity doesn't do anything to monitor asset licensing and we UAS publishers aren't allowed to implement our own monitoring systems either. It's completely based on the honor system. However, as I read the license you're allowed to use it on more than one computer as long as it's not being used at the same time on both.
     
    SVC-Games likes this.
  47. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Oh really? Wow, I've been using a "safe copy" that didn't use any external assets on my laptop and the "real project" on my PC. When I've made changes at home I had to apply them on the other project and viceversa... I guess I've been working twice for nothing. lol
     
  48. cfoster

    cfoster

    Joined:
    Aug 27, 2015
    Posts:
    6
    Thanks for all the replies - you have been super helpful.
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    You're welcome! :)
     
  50. cfoster

    cfoster

    Joined:
    Aug 27, 2015
    Posts:
    6
    Hi there - is there a reason why the maximum width of a collider is 1024? Ideally I need this to be bigger, else I will have to cope with two colliders.