Jump to content

Spriter for Unity 4.3


Malhavok
 Share

Recommended Posts

Not sure - I haven't dealt with that property at all. I'm pretty sure you're right - z scale does nothing in 2d mode (and also means it's not your camera). There's a constant value defined for the z step size - try flipping it from negative to positive (or whatever). It SHOULD still be using z position to determine a raw drawing order in the absence of other overrides...

Link to comment
Share on other sites

After reading this I started messing around with the camera object. Apparently it was set to "Perspective", setting it to "Orthographic" fixed the issue.

Thanks for the input, I wouldn't have arrived at this conclusion otherwise.

Anyway on to my next question. I'm sorry for so many questions but I'm eager to make this stuff work. Whenever I try to load "Grey Guy"'s idle animation into the animation controller and then go to Play mode, I get this error.

Key count: 0 on curve ''
UnityEditor.AnimationUtility:GetCurveBindings(AnimationClip)
UnityEditorInternal.AnimationWindowState:get_allCurves()
UnityEditorInternal.AnimationWindowHierarchyDataSource:FetchData()
UnityEditor.TreeView:ReloadData()
UnityEditorInternal.AnimationWindowHierarchyDataSource:UpdateData()
UnityEditorInternal.AnimationWindowState:Refresh()

I get it only once after setting up the animation (maybe it happens when it loads the animation into the controller since it stays there afterward) and there doesn't seem to be anything inherently wrong with the animation other than a slight stutter when it goes from one animation to the next (like idle to walking), but I don't think it's related. I'd really like to know what this error is and if there's a way to avoid it, or whether it's actually as harmless as it initially seems.

Speaking of the stutter, any way to avoid that? It seems like during a transition between animations that use different textures, the two textures seem to be "warring" with eachother. Is there any way to make it stop doing that? Without cutting the transition time to 0 of course. Or is this maybe a known issue? I don't mind having to adjust it each time after import if I know how.

Link to comment
Share on other sites

@mythgarr, thanks for making this native importer.

I seem to be having a problem though, it works fine for the GreyGuy however it doesn't seem to be working for my own sprite I've made. I'm wondering, could this be caused by me using the newer version B7 to create my sprite?

The problem is it doesn't seem to display the final sprite, the hierarchy seems to be there, and all the individual pieces are also, however it's not displaying them. (I did import the images before the scml file)

3zKOp8fl.png

EDIT:

It turns out that I didn't hit "Key All" at 0 seconds for the animation, doing that fixed it

Link to comment
Share on other sites

Regarding the "stutter" when transitioning between animations.

Okay so I did some poking around the codes of the importer. From what I understand, the animation periodically updates the sprites used with the data from the character map. Do I understand correctly so far?

So what happens is, for a short time while transitioning from one animation to another, both animations will run their "update this-or-that sprite" calls, which causes the stutter.

For example, going from "Grey Guy"'s idle animation to his walking animation. The animations use a different texture for the head. The idle animation has the head more or less facing the screen, lets call this sprite 1. The walking animation has the head face more to the side, lets call this sprite 2.

The sprite is currently performing the idle animation, so the head is sprite 1. Now, we make the character walk, which will cause it to transition from idle, to walking. This will cause a transition to occur. During this transition (which only lasts a couple hundred ms), both animations are running. At some point, walking will call ChangeSprite() to swap sprite 1 for sprite 2. However, since the we are in middle of a transition, idle animation is still sort-of running. Which means idle's script calls will fire as well. So some milliseconds after sprite 2 has been called in by walking, the still-running idle will suddenly call ChangeSprite() again, and swap the head sprite back for sprite 1. This continues going back and forth until the transition is complete, and only walking will be running, which will swap sprite 2 back in if it hasn't already.

Of course, all of the above can be prevented if you just make the transition happen instantaneously, but of course this is inelegant at best, and will just look bad at worst (compared to all the other, much more smooth animation).

My question here, is, since I'm quite inexperienced with Unity, is there a way to turn off an animation's script calls while it is transitioning to a new one? That way, in the above example, only walking will be performing any script calls from the transition's start, which means the sprites will change only once.

Otherwise there has to be some kind of change in how the animations are converted. Although I can't really think of anything.

I hope my explanation and question is clear.

EDIT:

Is it just me or is the Character Map script largely unfinished? It seems like it has the potential to do so much more than it currently does. Shouldn't it be able to dynamically swap entire texture sets? Not that I have a problem with fliddling around with it myself. The reason I mention this is just in case I overlooked something and someone else is like "Dude, it actually CAN do all those things.".

EDIT 2:

Okay I really hope I'm not overlooking something here. I'm about to tinker with the plugin itself to see if it can modify the way events work. I don't really want to do any unnecessary things.

Link to comment
Share on other sites

Sorry for the double post but my previous one is several days old, but I really wanted to share this.

I added a few lines of code to the importer and it completely got rid of any flicker during transitions.

Example:

http://dengar.meowcorp.us/test/

Don't mind the second button. That was just me fooling around to figure out how to swap textures at runtime.

It wasn't actually that difficult to figure out in hindsight. Most of the time I spent on it was figuring out what the code did, and also how Unity and C# work. Of course I'll share my custom code with anyone who asks.

I think I've done most of my preliminary testing and figuring out stuff and working out the kinks, so I can start applying it and work on my actual game project.

--

So I just wanna say, I wanna thank both Malhavok and mythgarr (and of course the guys behind Spriter) for giving me as a programmer a chance to work with animations without having to be a good animator or artist.

Link to comment
Share on other sites

Okay, in your project, in your Assets folder, find:

ThirdParty/Spriter2Unity/Scripts/CharacterMap.cs

And replace it with this version.

Then find:

ThirdParty/Spriter2Unity/Editor/Unity/AnimationBuilder.cs

And replace it with this version.

After that, you will have to re-import your .scml file or it will crash when you go into Play Mode.

I added notes to both files so you'll be able to see what I changed and why.

Link to comment
Share on other sites

The appreciation is appreciated :) Although I really just added a few lines of code to an already amazing tool.

I'm also going to work on bringing out the full potential of the character map. Right now it's really "just there". Dunno how long it'll take, it's more of a side project/hobby to me than anything else, but I'll keep you guys posted.

Link to comment
Share on other sites

Sounds awesome Dengar,

Please don't hesitate to contact Edgar directly if there are ver any questions you need answered. (lucid@brashmonkey.com) I should also point out that immediately upon the upcoming build release of Spriter (B8), Edgar is making finishing the Spriter data format doccumentation his top priority.

cheers,

Mike at BrashMonkey

Link to comment
Share on other sites

Hi! I am trying to use Spriter in Unity 4.3, using mythgarr's plugin. I got import working, animations playing, awesome. Now I cannot figure out what is the best (preffered) method of, for example, changing different weapons (or removing them whatsoever). I am a bit new to Unity, as well as Spriter, so I would appreciate greatly any advice.

I tried to use CharacterMap's ChangeSprite function, but, while it did change sprite (thus weapon), it quickly changed it back again. As i understand this function is called almost every frame...dunno why? Isn't it a performance issue? Anyways, if anybody with a bit more Unity+SPriter experience could shed some light on this, I would appreciate greatly!

Thank you in advance!

Link to comment
Share on other sites

Hi, I'm completely new to Unity, so I'm probably missing something obvious, but I'm having problems figuring out how to use this. This is what I've done:

I'm using the character from the platformer pack, to be sure that there's nothing wrong with the animation itself. I've downloaded and unzipped Spriter2Unity from Github, and replaced the two files updated by Dengar. I then copied that into the Assets folder of a Unity project.

Then I copied the PlatformerPack folder into the Assets folder project and started Unity. The conversion program runs and creates a blue box called Player, containing the animations. But if I select an animation, the preview window states "No model is available for preview. Please drag a model into this preview area." And nothing is shown if I drag the Player into the scene.

What am I doing wrong?

Link to comment
Share on other sites

Hi! I am trying to use Spriter in Unity 4.3, using mythgarr's plugin. I got import working, animations playing, awesome. Now I cannot figure out what is the best (preffered) method of, for example, changing different weapons (or removing them whatsoever). I am a bit new to Unity, as well as Spriter, so I would appreciate greatly any advice.

I tried to use CharacterMap's ChangeSprite function, but, while it did change sprite (thus weapon), it quickly changed it back again. As i understand this function is called almost every frame...dunno why? Isn't it a performance issue? Anyways, if anybody with a bit more Unity+SPriter experience could shed some light on this, I would appreciate greatly!

Thank you in advance!

I am not the original creator, and I can't really speak for them, but I did wonder for myself why the ChangeSprite function is called, not every frame, but every keyframe. I did eventually come to some sort of conclusion, but I will explain that in a bit.

First of all, ChangeSprite() is in fact, NOT meant for weapon swapping or skin swapping or anything of the sort, and is not meant to be invoked manually. You see, during the animation, the sprites are not always static. A character may blink, or the graphic for the hand may change from open to closed, etc. In Spriter, you achieve this by changing the texture of one of the objects on a certain keyframe, in the blinking example, you swap the head-with-its-eyes-open for the head-that-is-blinking texture, but only during a single keyframe.

When you import a .scml file, the importer goes over every single keyframe of an animation, and maps out which objects (body parts) use what texture for that keyframe, and creates an AnimationEvent for every object in the Sprite to assign that texture to that object for that keyframe (this is also what causes the flicker if you don't patch the importer with my modification, but that has little to do with your current problem).

If you want to completely change a body part (or weapon, in your case) completely at runtime, you should not resort to ChangeSprite() (although I understand why you would think so, the name of the function is actually a little bit misleading), since it just resets the texture to its previous state at the next keyframe. This is actually fine. There is an easier and much better way to achieve this.

You see, the ChangeSprite() functions draws information from the CharacterMap object itself.

Let me break it down:

1) ChangeSprite() is called during a certain keyframe

2) The parameter for ChangeSprite() is a "link" to a variable X inside the CharacterMap

3) Unity applies the texture assigned to variable X to the sprite

So if you want to change that texture, just change variable X.

Lets say in your example, the default weapon your Sprite is wielding is Sword1.png

-Examine the Character Map for your sprite, and find that Sword1.png, you can do this straight from the editor in the inspector

-Have your new sword, Sword2.png somewhere in your project

-Drag and drop Sword2.png into that value field

-Your Sprite should now be wielding that sword in every frame of every animation

-Change it back by dragging and dropping Sword1.png back into that field

Of course you'd want to change it at runtime. Then you'd have to know the exact index for Sword1.png. It'll look something like [CharacterMap instance].folders[x][y].Sprite.

I understand this is very unwieldy, but I'm assuming (and this is a very big assumption but I personally believe it's likely) that the CharacterMap class is actually an unfinished product, and is actually supposed to have a way to change textures more dynamically.

Since my own project relies heavily on this functionality, I intend to homebrew something that does this. But since it's just a hobby and I do have a lot of other things to take care of, this might take a while. But maybe you could experiment with it yourself.

I hope my explanation is sufficient. I have a hard time explaining all this technical stuff to other people.

Hi, I'm completely new to Unity, so I'm probably missing something obvious, but I'm having problems figuring out how to use this. This is what I've done:

I'm using the character from the platformer pack, to be sure that there's nothing wrong with the animation itself. I've downloaded and unzipped Spriter2Unity from Github, and replaced the two files updated by Dengar. I then copied that into the Assets folder of a Unity project.

Then I copied the PlatformerPack folder into the Assets folder project and started Unity. The conversion program runs and creates a blue box called Player, containing the animations. But if I select an animation, the preview window states "No model is available for preview. Please drag a model into this preview area." And nothing is shown if I drag the Player into the scene.

What am I doing wrong?

You probably didn't import all of the associated graphics before importing the .scml file. You have to import the graphic files first, and THEN the .scml file.

If that's not the case, then I'm not sure.

EDIT: I just remembered, even if you DO import them in the right order, it will show nothing in the previewer while selecting an animation. That is because the animation objects themselves don't contain any graphics. They're just instructions that alter the state of the Prefab's child objects. So what you're experiencing might be normal. If you want to look at the animation, try demo'ing them in Play Mode.

You have to attach an Animator component to the Prefab, and then create an Animator Controller and attach it to the Animator. In the Controller, you can just drag and drop the animations, and control them by making transitions. If you want to know more, there are video tutorials on 2D animation in unity everywhere on youtube, and also on the main Unity site.

Of course, maybe I could be wrong about all this. I only started poking around in Unity about two weeks ago. I think I'm right about most things though.

Link to comment
Share on other sites

Thanks! With your help, I now have a visible animation working in my Unity project.

The part I hadn't done (besides the part about the Animator, which I knew nothing about before) was clicking on each image file, and changing the type from Texture to Sprite. (Is there a way to set that to default to not have to go through every image like that?)

Link to comment
Share on other sites

Hey, just a quick, wild speculation...

My question is -- does anyone in the Unity side of things know which version of .NET they support? How far up are they? I need to use *at least* 3.0, I believe (because my mapping functions rely on Action. It may even be possible to port it back to .NET 2.0 (if I manually create an Action), but no promises on that -- I haven't done enough exploration into it to see if that'll work.

Let me know, if anyone from Unity has some technical knowledge or can hunt it down for me!

Unity's mono version is roughly equivalent to .NET 3.5. You are free to use lambdas, Funcs, Actions, etc.

Link to comment
Share on other sites

I can't seem to get this to work, I replaced the 2 .CS files, but the importer just locks up everytime while "Importing Small Assets". This is with Unity 4.3.1.

http://cl.ly/image/1A223b0j342N

It's pretty frustrating that 2 years after Spriter started, we still don't have a working Unity importer :(

Hopefully we can figure out what is breaking... I'm not sure how to even begin debugging these scripts though.

[update] It seems to work ok with our simpler animations, just struggling with the main character who has a lot of different anims. I'll keep trying to isolate what's causing it.

Link to comment
Share on other sites

Oh I haven't been dealing with this stuff long enough to know what causes this. A lot of people seem to be able to use it just fine. Even you yourself admit that the problem doesn't occur with every single animation.

Here are some guesses

1) Are you absolutely sure that you have imported all of the graphics files before importing the .scml file?

2) If yes, is it possible that one of the files might be corrupt or strange?

3) Are you using any other plugins?

Have you tried the Unity forums or Unity Answers? There's a number of users who are experiencing similar issues.

Link to comment
Share on other sites

Actually it does work! It just appeared to be frozen, but actually just needed about 13minutes to chew through the animations.

It's almost like there's some weird exponential performance issue going on. I tried deleting random animations from the file, and saw these results:

3 Animations - 5 seconds to import

6 Animation - ~1 minutes to import

10 Animations - ~3 minutes to import

24 Animation (ALL) - 13 minutes to import

Modifying any of the animations seems to cause a full 13 minute rebuild pass as well. Luckily for us, this is a port, so we don't really need to iterate, otherwise this could be a deal breaker.

Another issue I've found is that alpha is not supported. It's fairly easy to hack in after importing, but again this would be a major workflow issue if we had to iterate.

Link to comment
Share on other sites

Have you tried using a process of elimination to figure out exactly which file or files are causing the problem?

I still think this may be a problem with Unity itself, rather than the importer.

As for alpha, uhhh, that's the value that determines visibleness right?

It doesn't carry that over?

Link to comment
Share on other sites

Ya I tried process of elimination to try an narrow it down, but it doesn't seem related to any specific animation, just to number of animations contained within a single file.

Most of our characters have <10, and they all import fine. Our main character, has 24 and it brutally slow to import. But I delete some of those then it begins to import faster and faster.

I'll likely add a ton of API's to CharacterController, for better runtime features, but pretty stumped on where to begin with the parsing stuff.

Anyways, I'm just happy to see it running at this point :)

And yes, Alpha = visibility, if you fade something in Spriter, it won't be represented in Unity. I can hack it in after the fact by just setting the color.alpha = 0 for the various sprites within Unity's Animation Timeline.

Link to comment
Share on other sites

Hello.

Does anybody try to change 'Alpha' on several sprites, and apply on unity?

I have tried to use this plug-in with my animation which has some alpha-changing, and I found that it didn't work.

if someone solves this problem, plz answer me.

Sorry about my poor english. :)

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.

 Share

  • Recently Browsing   0 members

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