Jump to content

Spriter for Unity 5.0


Dengar

Recommended Posts

What's an origin point?

 

 

If I switch to this version of Spirter2Unity, will it overwrite the prefab I had made from the old one? I want to try your solution since it's newer but I'm close to finishing my game and I don't want to break anything.

 

Either way this seems really nice, and I'll try it with my next project either way.

 

If you REALLY want to do me a favor, backup your project, remove Spriter2Unity, then add Spriter2UnityDX, then reimport your .scml file, then tell me what happens.

Link to comment
Share on other sites

What's an origin point?

 

 

Origin point is the anchor point of your image, all positions are relative to it, and it's the rotational center of your image. By default, in Unity, all images are center-aligned, but in Spriter, this is customizable.

 

You see in the Torso of brad, his origin point is down by his belt buckle. When imported into Unity, this is not taken into account, and he's aligned as if his origin point was in the middle of his chest.

 

That's only my guess to what is going on... for some reason none of them will import properly.

4a0ac1f2994b1dacad171d4377a40d94.png

 

Digging into it a bit more... it seems to have to do with setting the 'Pivot' of each Sprite to x:0, y:1, which is causing all the sprites to have incorrect pivot/origin points.

Link to comment
Share on other sites

Ya, what's happening, is it's using the Global pivot_x and pivot_y setting for each sprite:
settings.spritePivot = new Vector2 (file.pivot_x, file.pivot_y);

 

But it's ignoring the pivot_x and pivot_y overrides that are assigned to each Timeline<> entry.

 

Here you can see an example of our Racoon character, the default pivot for his parts are x:0,y:1, but each part has a custom pivot defined in each frame (it doesn't typically change):

http://gyazo.com/725bb6e8e6b1dbd979d3129dce5532e1

 

This results in all sprites being Top-Left aligned, and ignoring the correct Pivot Points defined in Spriter.

 

I'm not even sure why pivot_x and pivot_y are defined on the File<> element, since there doesn't seem to be any way you can change it from the default.. Maybe to support exporting from external image editors? 

Link to comment
Share on other sites

I did not know that you can change the pivot point while animating. Probably because I could not think of a reason why you would have a different pivot for each frame of an animation. That said, you probably have a reason for it (I'm interested in hearing why).

 

I'll consider this a subject for my next update. Not sure when I'll get around to it though. I have some other things to do.

 

I'm not even sure why pivot_x and pivot_y are defined on the File<> element, since there doesn't seem to be any way you can change it from the default.. Maybe to support exporting from external image editors? 

 

Well probably because putting them on every frame of the animation is a waste if it doesn't change from the default? I use the pivot on the <file> element PRECISELY to set the pivot on the file in Unity. If I didn't do that, I'd have to use all sorts of funky maths to make sure the sprite parts don't get misaligned.

 

EDIT: The real reason why it's there, is (most likely) so Spriter knows what the pivot point default is. Remember, you can set the pivot on textures that aren't even used in the current animation. And then add them later.

Link to comment
Share on other sites

I did not know that you can change the pivot point while animating. Probably because I could not think of a reason why you would have a different pivot for each frame of an animation. That said, you probably have a reason for it (I'm interested in hearing why).

You usually won't need it for basic character animations, but one example would be a hammer being held by a character, it could rotate freely from the hand or arm using the end of the handle as a pivot point. Then when the hammer is dropped it's center of rotation would change to closer to the handle. Another example is a weapon like a staff where the wielder is switching from hand to hand, and shifting the grip along the staff.

You could do the same types of things with dynamic bone reparenting, but in some instances it is easier and more intuitive to do it by switching pivot points.

Link to comment
Share on other sites

I did not know that you can change the pivot point while animating. Probably because I could not think of a reason why you would have a different pivot for each frame of an animation. That said, you probably have a reason for it (I'm interested in hearing why).

 

I'll consider this a subject for my next update. Not sure when I'll get around to it though. I have some other things to do.

 

We don't change it while animating, we have a "Key" animation, where we setup all the sprites, and adjust their pivot points. Then we copy that anim as the starting point for all other anims.

 

I'd argue this is core functionality of the plugin, and hopefully would be higher priority than minor issues that do not cause broken animations to be created.

 

When we built these animations (2013-2014), I don't think Spriter had the ability to edit the Pivot Points of the images themselves, of if it did, we weren't aware. The only way we knew how to do it, was setup a timeline, adjust pivot points there, and duplicate. I suppose I could hand-edit the SCML files, and move the values into the File<> element, but we have about 30 of them, so it's quite time consuming. 

 

Here's a link to the Ratcoon SCML if you'd like it for testing. It's very simple, only 3 animations (key, idle, run) and 7 images:

https://www.dropbox.com/s/05zv92qu9xo90qh/ratcoon.zip?dl=0

Link to comment
Share on other sites

Just spent some time playing with your SpriteSwapper, and I've extended it a bit already.

 

Rather than swap slots by index, which can be confusing, and prone to error, I've added the ability to swap by name. So now we can do stuff like this:

//Blink!swapper.Swap("head", "head_blink");yield return new WaitForSeconds(.1f);swapper.Unswap("head");//Randomly strum guitarwhile(true){     swapper.Swap("strum_hand_0", "strum_hand_" + Random.Range(0, 5));     yield return new WaitForSeconds(.2f);}

I'll commit this to Git and you can choose whether to accept :)

 

The one pain point I've found so far, is the need to add each swapped image inside the timeline in order to have it added to SpriteSwapper. Then when swapping, I end up fighting these timeline swaps that I don't really want.... It would be nice if SpriteSwapper could be added manually within Unity, and you could swap to any of the sprites in the entire animation.

 

Best workaround right now, is to just create a dummy animation, and add a bunch of keyframes, for each image you want to swap. Not a horrible workflow, but feels a bit hacky.

Link to comment
Share on other sites

The one pain point I've found so far, is the need to add each swapped image inside the timeline in order to have it added to SpriteSwapper. Then when swapping, I end up fighting these timeline swaps that I don't really want.... It would be nice if SpriteSwapper could be added manually within Unity, and you could swap to any of the sprites in the entire animation.

 

Best workaround right now, is to just create a dummy animation, and add a bunch of keyframes, for each image you want to swap. Not a horrible workflow, but feels a bit hacky.

 

I'm afraid I don't quite follow what you are trying to use the sprite swapper for here. Can you like break the process you have in mind into steps? Maybe with an example of what you're trying to do, because I'm afraid I'm drawing a blank as it is.

 

 

I'd argue this is core functionality of the plugin, and hopefully would be higher priority than minor issues that do not cause broken animations to be created.

 

Not sure about 'core functionality' given the fact that I didn't even know that Spriter worked like this, and it only happens under very specific conditions. That said, I already said I'd work on it next time I work on it. I just don't know when that'll be. Two straight weeks of devoting every drop of my free time to this has kind of worn me out.

Link to comment
Share on other sites

Sure, to explain a bit more. We have a dude, he holds a guitar in every animation. Idle, Walk, Run, Solo etc:
cdd1e9d57f917ed43691f35b2a5cf571.png

 

We don't use Spriter to swap his hands, as that would be very time consuming, and not allow us to alter the tempo. Instead we do it in script. Using the SpriteSwapper we randomly swap hands a few times a second, totally independent of the animation he's in. 

4ebb24e839f0d2a862d75abbc0621b41.png

 

This way he can walk, run, solo etc, all while strumming his guitar, saving us a lot of time. We can also speed up or slow down his 'strumming speed' depending on the song being played, without having to speed up the entire animation.

 

Now the issue is, because we never swap his ChordHand in Spriter, SpriteSwapper is never assigned when the Prefab is created. In order to make SpriteSwapper appear, with the valid sprites, I need to create a dummy animation, with 5 keyframes, one for each hand sprite I want to swap through code.

Link to comment
Share on other sites

The ideal approach  I think, would just be to loosen the restrictions, and allow SpriteSwapper to swap to any of the images included in the SCML file. Just inject a List<Sprite> of all sprites into each instance of SpriteSwapper, and then we could modify the Swap() fxns to look there.

 

Then, we can manually add a SpriteSwapper to any object, and swap arbitrary sprites by name. This would be quite a bit more flexible, and should be relatively easy?

 

Ideally the system would be smart enough to retain a custom SpriteSwapper script if it was placed on an Object manually, but if not that would be Ok. We could always attach the SpriteSwapper(s) via scripting in the parent object.

 

 

Two straight weeks of devoting every drop of my free time to this has kind of worn me out.

 

Understood. I don't mind trying to step in and contribute. I'll see if I can get the allSprites thing figured out and send another pull request. 

Link to comment
Share on other sites

Ah yes see. I didn't actually create the Sprite Swapper with that kind of functionality in mind.

 

The Sprite Swapper is driven by the animation, not by script. It's meant to account for texture changes you do in Spriter. If they don't happen in Spriter, it's no use adding such functionality to the Sprite Swapper. The importer is meant to import Spriter projects and make them usable in Unity. Anything that falls outside of that scope falls to the hands of the user, doesn't it?

 

If you want to randomly change the texture every few seconds through script... Just write a script that does that? Am I thinking about this from a weird angle?

 

Again: Other than replacing the textures that are used by the Sprite Swapper, the user is not meant to interact with that component.

Link to comment
Share on other sites

Hmmm, my thoughts are that the Swapper could easily be injected with the references to the sprites that we need to work with, and would be so simple to implement there, that it kinda makes sense for it to just be the one to handle it. 

 

I think the purpose of the tool is two-fold. Bring the animation into Unity, yes, but then also provide an API surface to manipulate the animations at runtime. One of the biggest benefits to this type of animation is the ability to swap different hats, armor, weapons etc on the same animation rig. 

 

I'm not even sure how I would implement that externally... since all the sprites are packed into a texture atlas by unity, how do I even get a reference via Script? Maybe I'm missing something... I've only ever used 2dToolkit before, and am still a bit of a Unity noob when it comes to low level stuff. I could drag and drop references to each sprite in the editor, but that could be a bit tedious when I just want to swap by string_name.

 

[Edit] Just playing around with swapping the sprites directly, from a parent script that has references to the individual sprites, and it actually works quite well, so maybe you're right and it's fine as is. 

Link to comment
Share on other sites

I'm not sure what causes the problem but it might be a pivoting issue.

 

Re: How to use with sprite atlas: No problem, just make references to the original texture. Unity automatically changes those references to atlas texture when the player is built.

 

It's all nice and all that people would like an API for Unity users to use is a great goal, but the thing you are trying to do is 1) something anyone can do with a simple script and 2) simply not the Sprite Swapper's intended purpose. This isn't just about "expanding its capabilities" but would in fact repurpose the thing for something else entirely. Maybe this is partly my fault in naming the Sprite Swapper thus. But it DOES, in fact, swap sprites, so that's why I came up with it. Maybe I'll give it a different name in a next version to avoid confusion.

 

I'll go in-depth on why the Sprite Swapper exists.

 

Basically, in Spriter animations, sometimes, a particular part has multiple textures. Think of facial expressions, or maybe a slightly different angle, or maybe the guy's face changes color when he's poisoned, it can be anything really. The problem is translating that into something that's nonintrusive in Unity, because most of the "default" implementations had huge problems.

 

1) You could let the animation take care of changing the texture.

 

This creates a HUGE problem because this "hard codes" the textures into the animation, and I do not believe they can be changed at runtime. At least not in the animation. You'd have to jump through some hoops and play "tug o' war" with the animation to change your sprites. (for example to add different outfits, or do other things that are not animation related, but rather script related)

 

2) You could use AnimationEvents to change sprites instead.

 

Better. This does not set the textures in stone quite as much, and you could put references to the different textures on a component somewhere. That way the user can change the references on that compontent instead. This could be seen as a sort of "proto-Sprite Swapper". I abandoned this idea because it gets a bit messy when the user wants to add their own AnimationEvents.

 

3) Create a component that is directly manipulated by an Animation Curve.

 

This is what I ended up doing. The Sprite Swapper is added automatically and only when necessary (which is when the AnimationClip needs a way to change textures), after all, if the AnimationClip doesn't touch the displayed sprite, the user can just manipulate the Sprite Renderer directly with their own scripts.

 

In other words, if you want to change a texture by a means other than a Spriter animation (which is automatically through script), the procedure is VERY simple:

 

If there is a Sprite Swapper, you change the textures used by the Sprite Swapper.

If there isn't a Sprite Swapper (which is always when that part only has one texture to begin with), you change the texture used by the Sprite Renderer.

 

That's it. It's that simple. Nothing complicated at all. 

Link to comment
Share on other sites

Yep I got it. It just means I need to drag in references to the sprites, into the Unity Editor, in order to perform swapping, rather than just being able to use strings. But that's fine, no big deal. It's probably actually preferable once I get used to it :)

 

A name change would be good, to avoid confusion, and free up that component name if we want to make a true SpriteSwapper in the future.

 

In terms of the bug... it shouldn't be related to registration points. I've fixed them all for this specific SCML file, and they don't change mid-animation or anything, and the other 3 solos all work fine. Lemme know if you'd like a sample of the File. Here's another video showing what it should look like in Spriter, and comparing to Unity:

http://screencast.com/t/9VpQwv4gyb

Link to comment
Share on other sites

Yep I got it. It just means I need to drag in references to the sprites, into the Unity Editor, in order to perform swapping, rather than just being able to use strings. But that's fine, no big deal. It's probably actually preferable once I get used to it :)

 

There's also ways to do it without dragging references. You could use a Resources folder or an AssetBundle. That said, for purposes of that particular animation, I do recommend creating references since those textures will always be used while that "Bardbarian" is in the scene.

Link to comment
Share on other sites

Hi All,

 

I've searched Unity, BrashMonkey, Steam and a variety of other forums trying to figure out why my SCML file won't add the associated sprites into the prefab when it's imported.  I'm hoping someone here can help me understand this issue and why it's happening.

 

It brings in the SCML file, the body parts, but the final prefab itself only has a cube on display (not the character) and Bone_001 as it's first image (of course showing nothing).  The animations are all listed there, but it shows nothing.  I already got the Spriter2Unity 5.0 plug in working following the guide on that #13 github post, got rid of the warning, followed the instructions carefully, now the default grey guy is working fine, but if I bring in one of my characters, it keeps doing this invisible man act.

My end game is to get Spriter plug in to work with Adventure Game Creator plug in.  I don't think that's too far fetched, but this issue has now held me up for 5 hours and I'm practically spiting blood at this point.

 

Attached is one of my SCML files with sprites.  Any help would be appreciated.

 

Also these files all worked fine in Construct 2, I just would prefer to work in Unity with a plugin, rather than use my own oval imperfect reinvention of the wheel.

His name is Leek.   Leek Peelskin.

 

http://www.neonplanet.biz/Leek.zip

 

Link to comment
Share on other sites

When you say new version are you referring to the DX build?  

I have tried several plugs, one was the "streamlined" DX plug in, which I had little success with the 2nd was the non-DX version that had an up date earlier this year and required the modification of 4 different script files to get it to work with Unity 5.  

 

I read quite a few forum threads trying to get this to work, it's not like I was just poking around randomly and then posting here to get help.  I generally post only after I've exhausted my own ideas / resources and still don't have a clear course of action.

Could you point me to the latest version, just so I make sure we are on the same page?

 

Thanks :)

Link to comment
Share on other sites

Hello.

I'm having some problems getting my artist's spriter animations to behave correctly. 

Here is the issue I'm having http://screencast.com/t/63TVeoif

I'm using version 1.03 and I can't seem to get any spriter file to work correctly, so I am sure there is something wrong on my end. Do you have any idea what might be causing this? I can send you my artist's spriter project in a pm if that'll help. Thanks a lot in advance :)

 

-Alex
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...