Hello Guest

Author Topic: Z-Order / Depth bug only when I build  (Read 5649 times)

cloudcamaleoniv

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
Z-Order / Depth bug only when I build
« on: October 08, 2013, 07:36:17 am »
Well, the question is simple, but I'm afraid of the answer.

The z-order of my tk2dsprite components works great in the editor player. But when I export it (to web player, pc, android, doesn't matter), the z-order gets all messed up. The objects seems to "jump" randomly between z positions, sometimes one is behind another, sometimes not, and so on.

I'm using 3 cameras.

An ortographic one for my "main" objects, like the player
A perspective one for the "foreground" objects, that spawns above the player, to give a sense of speed and coolness :P
Another perspective one for the "background" objects, that spawns behind the players. I have lots of objects in this layer, and they will spawn randomly in randomly z-positions.

I've got a demo at www.playlouis.com/build/build.html

Click screen to begin. When the worm starts walking, press the UP ARROW to see the weirdness and press the DOWN ARROW to go back.

The strange thing is that this weirdness does not happen in the editor player.

So, could you tell me why does this happen and how may I fix it?

Thanks in advance.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Z-Order / Depth bug only when I build
« Reply #1 on: October 08, 2013, 11:28:57 am »
Which camera does the z order break in?
With the perspective cameras, do you have TransparencySortMode set to orthographic?

This is solveable, we just need to find out why its happening first :)

cloudcamaleoniv

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Z-Order / Depth bug only when I build
« Reply #2 on: October 08, 2013, 04:38:10 pm »
Well, the weirdness happens with the background camera. It's a perspective camera.

And yes, the TransparencyMode of the two perspective cameras was already set to Orthographic.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Z-Order / Depth bug only when I build
« Reply #3 on: October 08, 2013, 06:46:33 pm »
1. Are the z values actually arranged deterministically? Instead of being all the same?
2. Does this happen when only one camera is visible?

cloudcamaleoniv

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Z-Order / Depth bug only when I build
« Reply #4 on: October 08, 2013, 06:55:56 pm »
1. Yes, in the demo I showed, every background element is in a different fixed z position.
The far background image -> z: 270
The smoke image -> z: 150
The bush image -> z: 90

And so on. And they still overlap each other randomly.


2. Yes, I deactivated all other cameras, and the problem still persists.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Z-Order / Depth bug only when I build
« Reply #5 on: October 08, 2013, 07:08:47 pm »
Hmm. Thats really strange. Can you set up a really simple repro case for me to look at? I think it breaking on one of the cameras will be more than adequate. You can fill out the color channels if you have confidential info there.

cloudcamaleoniv

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Z-Order / Depth bug only when I build
« Reply #6 on: October 08, 2013, 09:07:00 pm »
Man, I feel ASHAMED. I found the error (my error). And it was very very simple. I made this script to ease the camera transparency change.

public class CameraMode : MonoBehaviour {
   
   public TransparencySortMode cameraTransparency;
   
   void OnValidate()
   {
      gameObject.GetComponent<Camera>().transparencySortMode = cameraTransparency;
   }
}

That way, my designer could easily make his scenarios. But I clearly forgot to replicate this line of code in the "Start" method. So, inside the editor, it works, outside it, the line is ignored.

I found it while I was making your test case, so thanks, man! You can check the demo again working at the same link above.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Z-Order / Depth bug only when I build
« Reply #7 on: October 08, 2013, 09:59:37 pm »
Glad its sorted :)

korn3l

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Z-Order / Depth bug only when I build
« Reply #8 on: October 10, 2013, 10:08:42 am »
This seems like the problem I had. There seem to be some problems with tk2dCamera (at least in perspective projection).
I had problems with the camera resetting or changing to past values the values I gave in the Inspector when I played the game.