Jump to content

Sprite Sorting Layer Problem


Recommended Posts

I am using Spriter Pro with Unity, with the help of https://github.com/Dharengo/Spriter2UnityDX exporter

I have some issue with the sorting of the sprite's Z Order.


The problem:

Sprite that are assigned to be at the back is appearing in the front after exporting.

Additional Notes:

  1. The spriter prefabs are generated via code. In other words, they are not placed in using the Unity Editor.
  2. I did set the exported prefab as a child of another object.
  3. Now this is the weirdest part,
    I have 2 game screens that displays the Spriter Prefab.
    However, in one of the screen, it is displaying fine, but on the other screen, it is not. Everytime.
    The methods used to display the display each time is exactly the same. (Using the same function).
  4. With some research, one of the solution is to switch on the "Apply Spriter Z Order" checkbox.
    This does resolve the Z Order issue, BUT, it also makes the Spriter Prefab always behind everything else. I need the prefab to be above some objects so that will not do.

The request:

I hope for an alternate solution to resolve the Z Order issue. Any help is appreciated. Thanks!

Link to comment
Share on other sites

I think I recall Spriter2Unity does not support animations which change their z-order throughout the animation.

You could try going to keyframe zero and choosing "copy z-order to all frames", then re-save and re-import to Unity and see if that fixes the problem.


-Mike at BrashMonkey

Link to comment
Share on other sites

Hey Mike, thanks for the quick reply.


I am sorry for the misunderstanding.

There is no change in the Z Order at any point in time. In other words, all the frames stayed in their z order throughout.


I would also like to iterate that, in one of my game screens, the z order stayed in the right place throughout the whole animation.

Do you have another possible solution?

Link to comment
Share on other sites

  • 2 weeks later...

Hi, I don't know if it's of any help but while making the older Spriter2Unity work with 2DToolkit I ran into a similar problem. In one animation, a helmet would appear normally at the beginning but then all of a sudden it would have its z-order changed. For no apparent reason.

I had a look a the files and the problem lay in Z_SPACING ( = 0.1f).


public const float Z_SPACING = 0.1f;

localPosition.z = ((ObjectRef)childRef).ZIndex * -Z_SPACING;

I thought it had to do with a precision issue kinda thing. Like when the animation is playing the float goes a tad bit crazy so instead of displaying a z-order of 0.23 it outputs 0.22(9) and it stays like that. So I multiplied it by 10. And my problem disappeared. Now, I haven't had a look at Dengar's version, I'm planning on doing so, but the bit of code that looks similar to bonus' code is this:


[XmlAttribute] public float z_index { 
	get { return z; } 
	set { z = value * -0.001f; } 

Where -0.001f is bonus' Z_SPACING, I guess? Would it fix it if instead of -0.001f it were -0.1f? I'm probably talking nonsense here and it may not be related AT ALL, but your problem looked very similar to mine so here I am, sharing my line of thought.

Hope you find an answer to your problem.

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.

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