Jump to content
bonus2113

Spriter for Unity 4.3 (Updated, Integrated)

Recommended Posts

I've decided to open a new thread for this implementation as the old thread is mighty out of date (especially the first page is misleading).

Spriter2Unity

Get it from GitHub: https://github.com/bonus2113/Spriter2Unity

A tool that converts SCML files into unity .prefab and .anim files Based on the original work by Malhavok (https://github.com/Malhavok/Spriter2Unity)

About

What it does:


  • [*:o70kr28x]for each entity in SCML file creates a Unity prefab
    [*:o70kr28x]each entity got it's sprites assigned as long as you imported these sprites before conversion
    [*:o70kr28x]for each animation in SCML file creates a Unity animation under the prefab
    [*:o70kr28x]sprites are changed during animations, so only 1 SpriteRenderer is used for each node in the spriter file
    [*:o70kr28x]an AnimatorController is created (if it doesn't exist already)
    [*:o70kr28x]an Animator component is attached to the prefab. It gets a reference to the AnimatorController.

Known issues:


  • [*:o70kr28x]Only quadratic, cubic, linear and instant curves are supported
    [*:o70kr28x]Mainline curves are not yet imported
    [*:o70kr28x]Only works with a "Pixels To Units" setting of 100
    [*:o70kr28x]Some animations throw errors when selecting/scrubbing through them in the editor. They work fine when running the game.

Important missing features:


  • [*:o70kr28x]Sounds
    [*:o70kr28x]Points
    [*:o70kr28x]Boxes

Usage

Copy the contents of the Assets folder into your Unity project's Assets folder or import the package from here. Any SCML files copied into the project will be automatically processed. Prefabs are created in the same folder as the SCML file.

Detailed:


  • [*:o70kr28x]Download this Unity package:
https://github.com/bonus2113/Spriter2Un ... itypackage
[*:o70kr28x]Open your Unity project.
[*:o70kr28x]Import your whole Spriter project folder into Unity.
[*:o70kr28x]With Unity open, go to the folder you saved the Unity package to and double click it.
[*:o70kr28x]Unity should pop up with a dialog asking if you want to import the assets, click import on the bottom right.
[*:o70kr28x]Unity should now import the Spriter2Unity package and then automatically convert your SCML files to prefabs. The prefabs will be in the same folder as the SCML files.

There's an example included which imports the GrayGuy character and animates him via Mecanim.

I'm currently working on the in-code documentation to make it easier for other people to contribute. You are very welcome to fork the repository and create pull requests!

If you have any questions feel free to ask them here. I'd appreciate it if bug reports would be done via GitHubs issue system (https://github.com/bonus2113/Spriter2Unity/issues), but I if you don't want to create a (free) GitHub account, this forum is fine as well.

Changelist

26th of June 2014:


  • [*:o70kr28x]Fixed ZIndex Animation
    [*:o70kr28x]Added an example
    [*:o70kr28x]Implemented Sprite changing into the native Unity animations

Share this post


Link to post
Share on other sites

Very cool. As I integrate Spriter into my own Unity project, I will try to send merge requests for anything I add.

Any idea how difficult it would be to add character map support? Since the Spriter philosophy on that is to have the game "apply" the character map, I imagine Spriter2Unity would need to add a component to the root prefab that has some CharacterMap operations, like which ones to enable. Depending on what gets enabled, it goes and modifies the sprite renderers.

Thanks!

Share this post


Link to post
Share on other sites

Awesome, if you have any questions regarding the current code, feel free to ask, I know it's still a mess in some places.

There actually used to be a CharacterMap component. This is the commit where I removed it: https://github.com/bonus2113/Spriter2Un ... dafdc2a09d

The problem was that sprite animation was handled via animation events (and not via a regular animation curve). Animation events unfortunately don't get triggered while playing the animation in the editor and there were problems with transitions.

I'll look into CharacterMap support after I'm back from vacation (1.5 weeks), but if you need it urgently you might want to start working on it yourself.

Share this post


Link to post
Share on other sites

Awesome work. I made a simple tutorial video for it:

Feel free to embed in the original post:

[youtube]http://www.youtube.com/watch?v=toYWWIejxO4[/youtube]

Also, I found a bug where it's playing back a certain animation incorrectly. If anyone wants to take a try at seeing what's wrong, please email me at lucid@brashmonkey.com and I'll send you the file (I can't share it here, as it's part of one of our commercial artpacks), and I'm also available for any other help.

Thanks for the great work from everyone responsible.

Share this post


Link to post
Share on other sites

Will join into the GitHub later, but for now I added:

if(parent.Scale.x*parent.Scale.y{
unmapped.Angle_Deg=360-unmapped.Angle_Deg;
}

to public SpatialInfo Unmap(SpatialInfo parent) in SpatialInfo.cs

Here's the whole function for copy pasting:

public SpatialInfo Unmap(SpatialInfo parent)
{
if (parent == null)
return this;

var unmapped = new SpatialInfo();

unmapped.Position = new Vector2(
Position.x * parent.Scale.x,
Position.y * parent.Scale.y);
unmapped.Scale = new Vector2(
Scale.x * parent.Scale.x,
Scale.y * parent.Scale.y);
unmapped.Angle_Deg = Angle_Deg;

if(parent.Scale.x*parent.Scale.y {
unmapped.Angle_Deg=360-unmapped.Angle_Deg;
}

unmapped.Spin = Spin;

return unmapped;
}

This handles children of mirrored bones (negative x or negative y scale, but not both negative)

and displays the character correctly

spriter2unityfixed.PNG

I see another importing issue with what seems to be the spin attribute, and I'm looking into it now.

EDIT: I'm having trouble figuring out where the 'spin' attribute is used. I see where Spin is set in SpatialInfo.cs in Parse, but I don't see it used anywhere. I see the Spin commented out from use in AnimationBuilder.cs, but that usage wouldn't change the direction of the spin at playback time. Where do I find the relevant code?

EDIT2: Also, will have to look into what's up with animation transitions. Seems like it's doubling up certain sprites during the transition

Share this post


Link to post
Share on other sites

Whoops, looks like I was a bit late to the party. Awesome that someone is resuming active work on this.

Does this include the fix for that frame flicker we talked about in the previous thread?

To elaborate: With the previous version, whenever you transitioned from animation A (for example, idle) to animation B (for example, walking), the sprite would spazz out during the transition because the textures keep swapping back and forth between animation A and animation B.

I provided a fix for this back in april. Was just wondering if that's been incorporated in any way.

I don't know much about github. Can other users contribute to a build?

EDIT2: Also, will have to look into what's up with animation transitions. Seems like it's doubling up certain sprites during the transition

Is this a different problem or the same problem as the above?

Share this post


Link to post
Share on other sites
Whoops, looks like I was a bit late to the party. Awesome that someone is resuming active work on this.

Does this include the fix for that frame flicker we talked about in the previous thread?

To elaborate: With the previous version, whenever you transitioned from animation A (for example, idle) to animation B (for example, walking), the sprite would spazz out during the transition because the textures keep swapping back and forth between animation A and animation B.

I provided a fix for this back in april. Was just wondering if that's been incorporated in any way.

I don't know much about github. Can other users contribute to a build?

EDIT2: Also, will have to look into what's up with animation transitions. Seems like it's doubling up certain sprites during the transition

Is this a different problem or the same problem as the above?

I'm not sure. I'll have to look into it. I'm used to using svn and cvs for version control, so I'll have to dig into GitHub soon and get caught up. I'm a bit busy at the moment with Spriter itself, but when I get a chance, I will try your fixes and see if they will fix my importing problems as well.

Share this post


Link to post
Share on other sites

@Dengar - It seems they integrated your code a while back, or figured out another way to fix it because this is a different problem. While experimenting I realized that animation blending does work. The cases where I saw both animations at the same time for a moment were for animations that don't share the same skeleton or body parts with eachother, which is to be expected, for now at least.

The more serious problem I'm having is that importing happens incorrectly sometimes. Objects will spin in the wrong direction. What's strange is using the same import script repeatedly will sometimes result in the correct spin, and sometimes not.

I wasn't able to get it working just yet, but I have a few ideas about what might be involved:

I enabled some log messages to try and track the problem in the function:

private void SetGameObjectForRef(GameObject root, Ref childRef, float time)

in AnimationBuilder.cs (line 263)

//Spin the object in the correct direction
var oldEulerAngle = transform.localEulerAngles.z;

The value returned from transform.localEulerAngles.z is inconsistent

There are screenshots of the debug logs. The value immediately next to 'old:' is transform.localEulerAngles.z:

unityimportlog.png

The one with red X ends up making the back_foot spin the wrong direction, and the check marked one works correctly. These are both the same exact code, if I reimport repeatedly it will (seemingly) randomly get one of these two results.

I think it might have something to do with the following from the Unity docs on Transform.localEulerAngles

Only use this variable to read and set the angles to absolute values. Don't increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate instead.

Unfortunately, replacing this code:

var oldEulerAngles = transform.localEulerAngles;			
if (oldEulerAngles.z - localEulerAngles.z > 180) localEulerAngles.z += 360;
else if (localEulerAngles.z - oldEulerAngles.z > 180) localEulerAngles.z -= 360;
transform.localEulerAngles = localEulerAngles;

with this:

var oldEulerAngles = transform.localEulerAngles;
transform.localEulerAngles = localEulerAngles;
while (oldEulerAngles.z - localEulerAngles.z > 180) transform.Rotate(0,0,360);
while (localEulerAngles.z - oldEulerAngles.z > 180) transform.Rotate(0,0,-360);

does not fix the problem, so if it's related to the increment problem it's elsewhere in the code.

On a side note, currently this doesn't read in or attempt to account the 'spin' property. I have some code to commit that will read the values correctly (currently it tries to read spin from instead of , but for the short term it's irrelevant since Spriter currently automatically uses the shortest direction of spin like the above code. It will be easier if we can resolve the above issue before rewriting it to take the spin values from the file into account.

Thanks again to everyone involved. Fantastic work.

Share this post


Link to post
Share on other sites

Hi!! I Just bought spriter pro (less than an hour ago :P) but it seems I'm doing something wrong when I'm importing to Unity...

I'm just importing one of the examples of the GameEffectsPack_Essentials folder. This is what I'm doing:

1) Drag the folder and the .scml file to a new folder in Unity (folder name is bunus_0, with 6 png files and the smcl file name is Bonus_effects.scml).

2) Execute Spriter2Unity.unitypackage.

But when the import is finished there are no new files in the folder where the .smcl is.

What I'm doing wrong? Thank you very much!! :)

EDIT: SOLVED -> I started a new project, and I import the package in the project creation (then copy all my assets from my previous project in the new one) and now it works!!

It seems it doesn't work for be a project created in an older Unity version?

Anyway I will continue in the new created project. Hope this help someone with the same problem! :)

Share this post


Link to post
Share on other sites

I started a new project, and I import the package in the project creation (then copy all my assets from my previous project in the new one) and now it works!!

It seems it doesn't work for be a project created in an older Unity version?

Anyway I will continue in the new created project. Hope this help someone with the same problem!

Share this post


Link to post
Share on other sites

Having trouble I am using Unity 4.5.0f6 with Spriter b10

The problem is when i try and import a scml it imports it and creates the animation files and the animator and the prefab.

What it does not do is fill these with any data it seams. The prfab comes with all bones and images attached but all the animations don't seam to of done anything. The individual animations are listed and are visible in the animator.

If I hit play no animation plays even if the default is something like the walk cycle.

If anyone has had a similar problem let me know.

Share this post


Link to post
Share on other sites
Does this still happen when you change the z-index of each greyguy?

Yes. It 's still happend. And my solution temporaliry is create 1 sorting layer for each greyguy. But that is not good when game has more spriter. Who has the better solution?

Sorry for my bad English :P

Share this post


Link to post
Share on other sites

FYI the importer doesn't currently work on the unity 4.6 beta.

You can't assign normal textures to objects, so the steps to get it to work are:

1) Import the folder with all the image assets (Spriter folder)

2) Select each textures and mark the texture type as "Sprite (2D and UI)"

3) Import the .csml file

If you fail to set the texture types first the imported prefab will have null textures assigned to the bones (and won't be visible, obviously).

Share this post


Link to post
Share on other sites

Hi guys, i'm new with spriter, i'm programming the art to a friend and have this issue when i import spriter2unity:

NullReferenceException: Object reference not set to an instance of an object

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.SpriteTimelineKey.Parse (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Timeline timeline) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/SpriteTimelineKey.cs:66)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.TimelineKey..ctor (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Timeline timeline) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/TimelineKey.cs:55)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.SpatialTimelineKey..ctor (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Timeline timeline)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.SpriteTimelineKey..ctor (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Timeline timeline)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Timeline.GetKey (System.Xml.XmlElement element) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/Timeline.cs:81)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Timeline.Parse (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.SpriterAnimation animation) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/Timeline.cs:56)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Timeline..ctor (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.SpriterAnimation animation) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/Timeline.cs:43)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.SpriterAnimation.LoadTimelines (System.Xml.XmlElement element) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/SpriterAnimation.cs:109)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.SpriterAnimation.Parse (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Entity entity) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/SpriterAnimation.cs:90)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.SpriterAnimation..ctor (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Entity entity) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/SpriterAnimation.cs:73)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Entity.LoadAnimations (System.Xml.XmlElement element) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/Entity.cs:59)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Entity.Parse (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.ScmlObject scml) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/Entity.cs:51)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.Entity..ctor (System.Xml.XmlElement element, Assets.ThirdParty.Spriter2Unity.Editor.Spriter.ScmlObject scml) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/Entity.cs:42)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.ScmlObject.LoadEntities (System.Xml.XmlElement element) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/ScmlObject.cs:72)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.ScmlObject.Parse (System.Xml.XmlElement element) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/ScmlObject.cs:55)

Assets.ThirdParty.Spriter2Unity.Editor.Spriter.ScmlObject..ctor (System.Xml.XmlDocument doc) (at Assets/ThirdParty/Spriter2Unity/Editor/Spriter/ScmlObject.cs:42)

Assets.ThirdParty.Spriter2Unity.Editor.Unity.ScmlPostProcessor.ImportScml (System.String assetPath) (at Assets/ThirdParty/Spriter2Unity/Editor/Unity/ScmlPostProcessor.cs:75)

Assets.ThirdParty.Spriter2Unity.Editor.Unity.ScmlPostProcessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/ThirdParty/Spriter2Unity/Editor/Unity/ScmlPostProcessor.cs:62)

System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.

System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)

System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)

UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/AssetPostprocessor.cs:26)

Someone have this issue to?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×