Jump to content

Spriter for Unity 5.0


Dengar
 Share

Recommended Posts

Thank you @Pixelpoint! That script worked for me, perfectly. For my fellow non-coders, this is what I did:

1) Copy the script text from Pixelpoint's post above.

2) In Unity and with a SpriterPro enabled project (you added Dengar's Spriter package), create a new C# script (e.g. right-click your Assets folder > Create > C#Script

3) When the script appears in your Assets folder, note that the name is highlighted - replace the default NewBehavior text with "TexturePostProcessor" - spelling and capitalization matter. I then moved the script into the "Assets/Spriter2Unity/Editor" folder, since this is where other Unity editor-specific scripts go.   

4) Double-click the script to open your script editor. 

5) When the editor is open, remove the existing default script and paste the Pixelpoint script here. Save the script (Control-S).

6) Voila, now when you drag-and-drop folders or individual images into Unity, they automatically become Sprites.

I confirmed this with my own projects and GreyGuy. @Rendi Kristyadi, I wasn't able to reproduce your particular error with GreyGuy in an existing project with other Spriter animations. Have you tried bringing the project into a blank project to see if your other content might be causing the problem? Or have you tried opening a clean (un-edited) version of "player.scml" into the project? Perhaps you accidentally modified the project in Spriter and that's causing Unity to bug-out. In my case, I made no changes to the GreyGuy folder and it worked fine. Using Unity 5.3.1. I see, after re-reading Rendi's post - the issue at hand wasn't about import, but the interpolation during animation, a problem mentioned elsewhere on this thread. 

Link to comment
Share on other sites

Hey guys.

I have an issue I'd like to talk about.

We have some animations with "sprite swapping". When my character blink for example.

Looks like when I import those animations, The TextureCOntroller doesn't follow what we've done in spriter.

Even weirder, I have a few animations with no "sprite swapping" that are not taking the default sprite for the animation.

Anyone got this kind of problem?

Link to comment
Share on other sites

Sorry for the double post but I think I found the problem.

Looks like when you import the project in unity. The animations are using the TextureController to change sprites.

There is an array index that I believe is the one from the sprite's id in the scml.

I think the problem is that, the array doesn't have the same index as the ids scml file. Or something close to that.

For example, I have this:

spriter.png.82a818f2fa31b652f8167fe6f784

Link to comment
Share on other sites

It has been a long time since I worked on the texture controller, so even I don't remember how the texturecontroller does what it does. I do know, however, that the TextireController does not use the file id todetermine its array index. So the problem does not lie there. 

Link to comment
Share on other sites

Thanks for the answer Denglar. I figured that out yesterday. I can't seem to find the problem. I'm not that good with C# after all.

There is a lot i don't understand in this code.

I think I found where you build your array, but I don't know what's wrong and I don't even understand how you define your indexes.

case ChangedValues.Sprite:
  var swapper = child.GetComponent<TextureController> ();
  if (swapper == null) { //Add a Texture Controller if one doesn't already exist
    swapper = child.gameObject.AddComponent<TextureController> ();
    var info = (SpriteInfo)defaultInfo;
    swapper.Sprites = new[] {Folders [info.folder] [info.file]};
  }

  SetKeys (kvPair.Value, timeLine, ref swapper.Sprites, animation);
  clip.SetCurve (childPath, typeof(TextureController), "DisplayedSprite", kvPair.Value);
  break;
}

We are pretty far for something like: array = something;

 

Edit:

Spent my day on it trying to find a solution. It didn't work out. But I learned a lot about List and Dictionnary.

So I went back on Denglar's code with my new knowledge and find out what the problem was. Let me explain:

Sprites[] in TextureController is set by a function called GetIndexOrAdd().

private int GetIndexOrAdd (ref Sprite[] sprites, Sprite sprite)
{
  var index = ArrayUtility.IndexOf (sprites, sprite); //If the array already contains the sprite, return index
  if (index < 0) {									//Otherwise, add sprite to array, then return index
    ArrayUtility.Add (ref sprites, sprite);
    index = ArrayUtility.IndexOf (sprites, sprite);
  }
  return index;
}

This is called when the algorithm is going through every animation while importing the .scml. The index is used during runtime to know which sprite should be displayed.

I'm currently importing just the animation I need to put them in my player's prefab animator. The reason is pretty simple, I have more than 80 animations for my character and going through all of the in unity explorer is a pain in the *ss.

That's where the problem is coming from. Indexes in the newly imported animations aren't the same as my old Player's Prefab.

Plus, I'd like to be able to add new swapping sprites without destroying my prefab containing all my scripts, colliders, etc...

This was just an update. I'm gonna work on it tomorrow. I'll send you the solution I came up with.

Thank you for reading that boring monologue and I apologize for my grammar mistakes

Link to comment
Share on other sites

Hey guys, here's the solution I found to solve my problem. Here's what I've done and how to use it.

If you are like me and you've created a prefab a long time ago. There is probably a lot of component on it that you don't want to move every time you import new animations.

If you're using sprite swaping at runtime. You will eventually encounter somes problems.  Same goes if you only import a "some" animation and not all of them every time. See the algorithm in my post up there for better understanding.

HOW TO DO IT: 

The .scml containing a list of your sprites should be placed in the folder with all your other sprites.

You can also remove all animations from this file. Just keep folders and sprites.

568e9a5317635_Sanstitre.jpg.b2967ff24ef8

I've added an options in Edit/Project Settings/ Spriter2Unity:

You can now give a path to a .scml file.

There is a boolean too: True to use the new process and false to use the old one. Keeps you from erasing your path every time you want to change process

The new process will change the way the array named "Sprites" in TextureController is filled. It should enable you to create an array that looks exactly like the .scml you've put in the path. This means that sprite's indexes in TC don't depend on what you import but rather ids in your scml. That I believe should never move.

All you have to do is keep your scml up to date.

TextureController have a new variable called "Folder". This is the folder's id in your scml. It will be used in some processes.

 

Also, if you want to update all TextureController in your prefab, you can use the button in the editor (See picture).

Just make sure to instantiate folder in all TextureController. You should have to do that only once.

WARNING: It will not change any indexes in your old animations. You should import them all at least once and change them in your animator if you want to use new indexes.

FILE :

S2USettings.cs

S2USettingsEditor.cs

ScmlFollower.cs

TextureController.cs

AnimationBuilder.cs

 

I'm not sure that was really clear. If you have any questions, bugs or comments, just ask.

Works fine for me. I hope it will help somebody. Have a good day.

Link to comment
Share on other sites

How are you able to delete old animations from the prefab? Whenever I right click on the clip and click delete, nothing happens.

I don't want to reimport by deleting the prefab, as I have animation events I want to preserve :c

Could the importer be extended to also not include/delete old clips that are not present anymore in the spriter file? That would be optimal.

Link to comment
Share on other sites

21 hours ago, Bisoux said:

If your animations are nested in your prefab, all you can do is create a new one.

Use "Separate Folder" option in  Edit/Project Settings/ Spriter2Unity. Then you should be able to manage your animations more freely.

I don't see spriter2unity under project settings o:

But I managed to create a little editorwindow that allows me to delete the animations, though, using LoadAllAssetRepresentationsAtPath to load the clips, and DestroyImmediate to delete them.

Link to comment
Share on other sites

Hi guys.. Im new in spriter..
I had some problem
I tried to make simple stick figure animation, when in Spriter everything was right, but when I export in Unity, all part was not in place

stickyExport.png.0be1e43f34e8490802de486
it seems Unity dont get the Pivot, so unity drawing in from (0,0)
I open my .scml with notepad and what i see is all pivot goes to (0,1) like this => pivot_x="0" pivot_y="1"
why my .scml not saved my pivot when everything still goes well in spriter ? :|

Link to comment
Share on other sites

Hey Rnd. I had a similar problem the first time I tried importing my scml.

I had two depths of folder for my sprites in my spriter project.

Like:

  -> Head

  -> Body parts

     -> Hands

     -> legs

Spriter2Unity gave me all my sprites but they were totally misplaced.

Maybe you have the same problem? 

Link to comment
Share on other sites

@Rnd

To set the default pivot points (which should be done to all images BEFORE you ever use them in the canvas) is to double click on them in the files palette and then use the dialogue that appears to set the default pivot point. Once you do so, any time you drag that image onto the canvas it will have this pivot point which you set.  changing the pivot point in the canvas only sets it for that specific key frame, until it hits the next one... its a more advanced feature for very specific edge-cases in animating and should typically be avoided.  I'm not sure Spriter2Unity can convert those per-key frame pivot points into native Unity animations.

Link to comment
Share on other sites

It does not, and in fact it cannot. I mean sure technically if I used some really complicated math I could fake it, but it's very difficult to do and not very high on my priority list at all. I'd rather implement character maps before anything else.

EDIT: And before that, I'd like to do something about the anomalous curve issues.

Link to comment
Share on other sites

Character maps is definitely far more useful to most people. Typically when per-keyframe pivot=point adjustments are made, its because that user does not know about or how to set default pivot points, and they don't actually need any of the potential uses for per-key-frame pivot point changes.

Link to comment
Share on other sites

  • 2 weeks later...

Hello guys! 

Great tool, and thanks for all the hard work you've put into this!

I've gone through this thread trying to find a solution to a z-value problem I've been having but can't really find a reliable solution. 

On most of my animations one or several elements switches z-orders, especially between animations. For example idle->running. In spriter there is no change of the z-order between these animations, but in unity there is. 

I currently work around these issues in one of three ways: 

1) Create a gazzilion keyframes in spriter
Works in about 60% of the cases, but if there are not enough keyframes there will be moments with keyframe gaps where things get missaligned as if there was something still instructing a faulty z-order in absense of keyframes. Also resorting to this alternative break any hope of ever working with the animation again. 

2) Switch around with the z-order at current keyframes. 
This works in about 40% of the cases. I would assume this forces unity to adjust an otherwise faulty z-index, but sometimes the sorting is still off and in some cases this is not an option if you only have two or three sprites in the animation.

3) Redo the animation
Works in about 50% since the problems with the z-order has a new chance of occuring. This is usually the best approach but is of course extreamly tiring.

I've tried reimporting the animations, reimporting Spriter2UnityDX, the Apply Spriter Z Order checkbox in the Entity Renderer, and a bunch of other stuff on multiple occasions but these inconsistencies keep coming. Unfortunately I don't really feel confident enough to dive into the code yet, and I'm obviously aware that this is a very unspecific problem and hard to solve. I'm just wondering if I'm the only one experiencing this, which might narrow it down to that the problem lies somewhere within how I'm doing things.

As far as I know I'm not doing anything strange, I set default pivots and don't use any unsupported features of Spriter. I do have boneless sprites, but this issue happens to "boned" sprites aswell.

Peace!

 

 
 

Link to comment
Share on other sites

I had the problem a few day ago.

I've just put my "order in layer" in unity manually and unchecked "Apply Z order".

I believe I've also removed all z position in my sprite's transform.

Don't forget to double check that all your character's sprites have the same "Sorting Layer".

Hope it helps

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...