Jump to content

Spriter for Unity 4.3


Malhavok
 Share

Recommended Posts

We actually talked about this in the last few posts. Unity doesn't apparently import the alpha values at this point in time. I haven't gotten around to figuring out how to get the importer to do that, so for now either change the alpha values manually, or fiddle with the importer if you feel up to it.

Link to comment
Share on other sites

Now I once again have a problem I don't understand. I've made progress integrating the sprite in the game (using Adventure Creator). It took a while, but I got the parts to play together nice, and had the character walking around a scene, complete with transitions between idle and walking.

Then I closed Unity, opened up Spriter and made some changes to the animation (including making some use of the previously unused forward facing head, but I did not add any images that weren't already imported into Unity). When opening Unity again, suddenly the wrong images were used in the animations. (A hand where the pelvis should be, a leg instead of a foot, and so on…)

What have I done wrong, and how can I fix it?

Link to comment
Share on other sites

Hm... This is not the first time I heard of this but have never seen it happen myself. Did you re-import the .scml file? Have you tried deleting the existing prefab and THEN re-importing the .scml file? Perhaps the animations and the characterMap somehow got unaligned?

Link to comment
Share on other sites

I have tried re-importing, but not deleting the prefab. I wanted to avoid that, since other things is built on that, and recreating everything to do with the character each time an animation is changed would be an awful chore. Guess I'll have to do that, then…

Link to comment
Share on other sites

After deleting the prefab, and recreating all the stuff required by an Adventure Creator character (add an animator to it, place it in a new GameObject, add to that a Capsule Collider, a Rigidbody, and two scripts, put the right settings into all those, make that new GameObject a Prefab and set the right settings on that), I still get the same weird animation.

I guess I'll start over from scratch.

Link to comment
Share on other sites

That's kind of quick to give up isn't it?

Have you tried reverting the sprite to a more base version? You know from a time when the sprite wasn't all weird like that?

Keep a backup of your current one.

But there has to be a difference between the two.

Of course it's hard for me to think of solutions when I can't actually see what's going on.

Link to comment
Share on other sites

I've been able to reproduce it. Here's how:

* I deleted the unused animations. (Everything but walking and idle - I'm still working with the sample player from the Platformer pack.) Opening it in Unity - everything is still looking as it should.

* I then replaced that scml file with the original one. Starting Unity, I found the characters walking around with heads as feet, all messed up.

* Replacing that file with my earlier one got things back as they were.

So the problem seems to appear when there's things added to the Spriter file.

Link to comment
Share on other sites

Exactly what did you add to it? No extra textures right, but you added extra animations you said?

It still sounds like the character map and the animations get misaligned somehow.

Let me refer back to my previous explanation of how the animations and the characterMap interact.

Basically, on each keyframe, a bunch of function calls are fired. They'll all roughly say like "Set the texture of child A to texture B, which can be found at coordinates [X][Y]."

X represents the body part, whereas Y represents a specific iteration of said body part.

So if it, say shows a foot where the pelvis should be, that would mean one of two things:

-The Animation sends the wrong X value.

-The target body part is stored in the wrong X value.

One of those things must have changed somehow (don't ask me how, that's what I'm trying to find out) when you started playing with the animations.

EDIT: Oh can you tell me something else? This may or may not be important. Before and after the error, did anything change at al in the prefab's hierarchy? Did the prefab gain a new child or parent? It really shouldn't matter, but stranger things have happened in the world of coding.

Link to comment
Share on other sites

Exactly what did you add to it? No extra textures right, but you added extra animations you said?

No new textures, but some textures that were previously unused by any animation came into use.

EDIT: Oh can you tell me something else? This may or may not important. Before and after the error, did anything change at al in the prefab's hierarchy? Did the prefab gain a new child or parent?

Not besides getting new animations as children.

Link to comment
Share on other sites

Would you mind confirming my suspicion then? Although this is kind of hard to explain.

1) Select the character that has the problem

2) Go to the animation window (the one that shows the time line and a bunch of dots and stuff) (if it's not open, you can open a new one by going Window > Animation)

3) Along the top of the timeline are the AnimationEvents, little markers.

4) Double click an AnimationEvent. Any animation will do.

5) Look at the parameter, it will look something like this:

pelvis/back_thigh/back_shin/back_foot/p_foot_walk_a;5;1;idle

Disregard the last parameter, it's not very relevant to this. Focus on the first few parameters.

6) Determine from the blue parameter (the long path) what body part this event is about. In the example, it says back_foot/p_foot_walk_a, which probably means this is the back foot.

7) With your character still selected, look at the Inspector, and find the Character Map component. It should have a property named "Folders"

8) Open Folders, you'll see a Size value and a list of Elements

9) Go to the element that has the same number as the red number in the parameter you fished up in step 5. Open it.

10) You should see a few other properties, including one named "Files". Open it.

11) You should see a list of textures, which should all fit the same body part.

So tell me, do the textures correspond with the body part that the function call is associated with?

I hope you can understand this.

Of course, this won't immediately solve the problem, but at the very least it'll prove I'm on the right track.

If the mistake is somehow caused by the importer, fixing it is something that's going to take time. The problem is likely in the same area as the problem that doesn't import alpha values. Both of these require some major dissection and analysis. I may try to tackle it this weekend but don't hold your breath.

Link to comment
Share on other sites

So tell me, do the textures correspond with the body part that the function call is associated with?

No, they don't.

For example, I found "pelvis/chest/head/p_head_idle;5;0;idle"

Looking at the character map, the contents of element five is:

feet/p_foot_idle0.png

feet/p_foot_walk_a.png

feet/p_foot_walk_0.png

feet/p_foot_jump_0.png

feet/p_foot_hot_0.png

feet/p_foot_ladder_0.png

feet/p_foot_ladder_1.png

feet/ladder_guide.png

(I note that there are several empty elements in other Character Map folders, but I see that with the working project too, so maybe that's as it should be? I mention it anyway, in case it's a clue.)

I also find plenty of errors in the console (I didn't notice this before, due to my lack of experience with Unity): "Sprite not found!", "Argument out of range" and "IndexOutOfRangeException: File Id 7 fell outside of bounds 0" (for FolderMap.getItem from CharacterMap.cs:134). This also confirms your theory.

I don't know Unity well enough yet to be able to help you fix this, but if you want more help testing things, or anything else I can do, just let me know.

Link to comment
Share on other sites

The empty elements aren't a problem as long as they are not referenced, which, by all rights they shouldn't.

Except when something strange happens. Such as one of the parameters being bumped up by one for no apparent reason.

Out of curiosity, what body parts are at index 4 and 6? I'm assuming index 4 holds the correct textures.

Can you like, upload the .scml file that causes the error somewhere? If you can't I'll PM you my email address. I really wanna take a look at the file itself now because clearly something is fundamentally different about it.

For all intents and purposes it uses the same assets as Grey Guy right?

Link to comment
Share on other sites

Out of curiosity, what body parts are at index 4 and 6? I'm assuming index 4 holds the correct textures.

4 is legs, 6 is empty and so is 7. The head is in 8.

Exactly the same file in a working project only has five folders though, with the head at number 5, and the feet in 4.

Can you like, upload the .scml file that causes the error somewhere? If you can't I'll PM you my email address. I really wanna take a look at the file itself now because clearly something is fundamentally different about it.

I could, but I don't know if that'd help you. I used the same scml file in the project where I started from scratch, that's working. The problem came in updating the file, and not so much in the file itself. (I think.)

For all intents and purposes it uses the same assets as Grey Guy right?

Yes.

Link to comment
Share on other sites

4 is legs, 6 is empty and so is 7. The head is in 8.

Exactly the same file in a working project only has five folders though, with the head at number 5, and the feet in 4.

Curiouser and curiouser... So it's not actually the AnimationEvents that are the problem, but the CharacterMap somehow has empty elements. How many elements does it have?

I could, but I don't know if that'd help you. I used the same scml file in the project where I started from scratch, that's working. The problem came in updating the file, and not so much in the file itself. (I think.)

So.... The same .scml file that gives you this prolbem in one project, does not give the same prolem in a completely new project?

And when you then change the.scml file after that, the problem starts to occur, and suddenly the CharacterMap has empty spaces in it?

Link to comment
Share on other sites

4 is legs, 6 is empty and so is 7. The head is in 8.

Exactly the same file in a working project only has five folders though, with the head at number 5, and the feet in 4.

Curiouser and curiouser... So it's not actually the AnimationEvents that are the problem, but the CharacterMap somehow has empty elements. How many elements does it have?

Eight. No, wait a minute! I found something interesting here.

In the broken project, I can find one instance of the Character Map that's looking just like the one that's working. (Five elements, with the head at number five.) But there is also another instance with eight folders, in the same order but with three empty folders in the list (at number 1, 6 & 7).

The correct one (with five folders) is sitting next to the spriter file among the assets, but the other one is inside another prefab. The framework I'm using (Adventure Creator) requires the sprite to be the child of a prefab containing a capsule collider, a rigidbody, and some scripts. So that's what somehow only got partially updated when I changed the spriter file. After doing "copy component" on the fist one and "Paste Component Values" to the second, it's working as it should. We have found the problem, and a workaround.

My remaining questions now are: Is the copy and paste thing something I have to do when updating a sprite, or can it be automated, or have I done something stupid in my setup that's causing this that I should change?

Link to comment
Share on other sites

After some more research, I now know more, and I'm posting this info here in case others run into the same issue.

What went wrong for me was not any fault of the Spriter importer. It's simply that Unity can't handle nested prefabs (when you put a prefab into another). So if you put the prefab that the importer creates into another prefab, you will run into trouble when updating it. In my case, there was an easy solution, but if you make bigger changes to the animation, you will probably have to rebuild the prefab (the one in which you placed the sprite prefab) manually each time you update the sprite. There are rumors that Unity will support nested prefabs in a future version, but nobody knows when that'll happen, so until then, avoid them if you can.

Link to comment
Share on other sites

I figured it was something like that. Thanks for clarifying.

I'm assuming you CAN work with nested prefabs, it's just that when you update them while nested, it causes weird issues.

That said, it's always a good idea to find out if you can get away with putting as much stuff as you can in a single prefab rather than nesting them.

Link to comment
Share on other sites

I have both love and hate for Spriter. I love it as it has taught me how to animate. Flash never did, Swish never did, AnimeStudio never did, only Spriter was able to do that. This tool is very easy to use a caveman can do it.

But alas, I have come to my limit. Though I only have one (and only) complain, it's very troublesome for me. I use Unity to make games. And the process to convert my Spriter animation to Unity, eludes me. I just cannot comprehend it. I downloaded Python, created the required folders. Transferred the files and such. But nothing is working.

I have stopped using this software until a proper converter or easier procedure gets done. For now, I am using Unity's built-in animator (and/or sometimes Blender).

More power to BrashMonkey! Keep up the good work.

Link to comment
Share on other sites

Here's the instruction (usage) in Mythgarr's version of S2U.

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

I downloaded the zip. Extracted it. Did not find the converter.EXE. I figured, Mythgarr probably removed it and automated that process.

I copied the contents of the asset folder (third party folder) into my asset folder.

Copied the folder containing the sprites and scml file into unity asset folder.

I see the prefab, animations and the textures. But there are no textures attached on the prefab.

Do i have to attach the textures manually?

Thanks for the quick reply. Have a great day!

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