Forum rules - please read before posting.

Weirdness with sorting layers when loading from another scene

So I've been trying to track down this super weird bug where ocasionally my sorting layers will (apparently) go mental and my character will start punching through objects he was behind of in previous runs. 

For a while I couldn't figure out why this was happening as it appeared like it would work correctly one time and then incorrectly the next without me actually changing anything.

Then recently I managed to reproduce the issue reliably and it turns out that it happens when I load into the scene from another scene.

So recently I added a quick simple frontend scene just so you don't get loaded straight into the game. It appears that when I load the game from this scene and then click "start" to go in the game scene, I get the sorting layers problem. If I load straight into the game scene, everything is fine.

Anyone ever encounter this?

I should note that the frontend scene doesn't use any Adventure Creator stuff, it's just a bunch of sprites with a simple onclick handler to load you into the game. One assumption I am entertaining is that maybe I should have the frontend be an AC scene as well and then actually use an Engine.ChangeScene action to load my level cause maybe this ensures that some AC stuff is properly initialised when I load into the game level? I don't know I am just trying to guess what might be happening...


  • You shouldn't have to resort to using a frontend scene to counter a bug with AC - better to solve it at the source.  Could you explain your set-up / give steps to reproduce?  It may be useful to make a copy of your problem scene, and reduce it's complexity to just the bare-minimum needed to show off the problem.
  • I am sorry I think I didn't explain what happened very clearly!

    I didn't create the frontend scene to counter a bug with AC! I had to create a frontend menu regardless as my demo didn't have one and it felt a bit wrong that it loaded you straight into the game.

    When I added the frontend scene though what now seems to be happening is that when I load the game starting at the frontend scene and then click "start demo" which in turn loads the game (AC powered) scene, the sorting layer stuff doesn't work properly anymore and my character overlaps parts of the scene that he shouldn't be (and that indeed he doesn't if I load the game scene directly!)

    I am really unsure as to how or why loading the same scene directly or via another scene would affect the sorting layer behaviour!
  • I understand now, but you still haven't given me enough detail to reproduce this - my own tests of loading the 2D Demo from a non-AC scene work just fine.

    It's not clear if this is a bug, or that the player prefab is not correctly set up.  Try using the Brain prefab from the 2D Demo (AdventureCreator -> 2DDemo -> Resources), and see if it then works.

    You could always make your frontend scene an AC one - by using the Engine: Manage systems Action, you can disable all it's systems for the scene's duration.  But, I'd prefer to fix it.  If you have to PM me a package with the two scenes for me to see it for myself, please discard anything and everything not completely necessary to show off the problem.
  • I just tried it with Brain2D and I am getting the exact same behaviour (loading directly in the scene all looks fine, loading through the frontend scene sorting layers go wacky)

    I can look into making the Frontend scene an AC scene, in the meantime I'll send you my project too if you want to take a look. 
  • FYI I decided to turn my Frontend scene to an AC scene as I needed to run some ActionLists when Frontend buttons get clicked anyway and this did go away when I did that. So it does look like it's the fact that I am loading from a non-AC scene into an AC scene that makes it fall over.

    I know you said it works fine on 1.42 but I thought you might want to know anyway.
  • edited February 2015
    Yesterday the exact same issue happened to me. I have one start screen (only logo and a "start Game" menu button, which changes to scene 1) and Scene 1. When I started Scene 1 directly, the sorting was fine (Sorting Layers: Player: 5, Background Image: 0). But when I accessed Scene 1 via the start screen, my Player was hidden behind the background. I tried around a bit, restarted unity a couple of times. Then I changed the background layer to -5 and back to 0 and to -10, and so on. And suddenly it worked again. I still don't know what caused and what solved this issue.
  • I get the same issue. I have three intro screens - two logos and an intro scene - and then I go into a main menu screen and from there load the game.

    I am using 2dToolkit to create the sprites for my game / character, which seems to work like a charm.

    What then happens is I transition from the first game scene to the second via a cut scene and then when I land in the next scene the sorting map is no longer working.

    Is a bug that I've had for a long time - is it something to do with the scene unloading the character as he is no present in the bridging cut scene.

    Happy to create a stripped back build to send to you, Chris?

  • That's always a last resort.  And it's still present in 1.42c?  Replace your player with the Brain2D prefab and see if it works - if so, it'll be an issue with the way your prefab is set up.
  • edited March 2015
    It's occurring again in my Unity5 AC1.42c project. Starting scene 1 directly: Player char sorting layer is fine. Accessing scene 1 via the Titlescreen scene: Player char is behind all other layers.
    The workaround I'm using now is to simply give everything that should be displayed behind the Player Character a negative sorting layer value. My backgrounds are -1 now and everything is fine.
  • edited March 2015
    Thanks for posting the workaround, but I'd be happier if it didn't have to come to that.  Does it work if you have your player prefab present in the Titlescreen scene?

    Also, what's should the background/player sprites actually be, and what are they instead when it doesn't work?
  • edited March 2015
    I noticed that the player prefab has "Order in Layer: 1" when it's in the "Resources" folder, but as soon it is dragged into the game, the instance there has "Order in Layer: 0", which can't be changed and snaps always back to zero.

    I just tried the following:

    Test 1:
    - In the resources folder, the player char prefab has "Order in Layer: 1"
    - I placed the player char prefab outside of the visible area of the start scene
    - This instance of the player char now has "Order in Layer: 0"
    - started start scene, the player char instance still has "Order in Layer: 0"
    - I went to scene 1, where no player char instance was placed manually before (Background picture has Layer 0)
    - player char runtime-instance now shows "Order in Layer: 1" and is visible

    Test 2:
    - In the resources folder, the player char prefab has "Order in Layer: 1"
    - No player char prefab was placed in start scene, nor in any other scene
    - I started the start scene, the new player char instance has "Order in Layer: 0"
    - I went to scene 1 (Background has Layer 0)
    - The player char runtime-instance showed "Order in Layer: 0" and was not visible
  • OK, good detail, thanks.  But what's the intended order, i.e. what's your Sorting Map telling the Player's sprite order to be in scene 1?
  • *Facepalm* I've found the reason behind this issue. Of course it was no bug but my fault:
    The Default Sorting Map of the start scene was set to "Order in Layer", but the sorting maps of all other scenes were set to "Sorting Layer". Once I set the Default Sorting Map of the start scene to "Sorting Layer" as well, everything works fine again. Sorry for wasting your time again :(
  • I was going to post to say "the issue has come back for me" and then I saw humaldo's post and I thought maybe I've got the same problem, but I don't this that's the case for me...

    I've got all my sorting maps set to "Order in Layer" which is what I want them to be affecting.

    The moment I leave one scene and go to the next my character's layer stops being affected by the sorting map (and not being an AC scene doesn't seem to have to do anything with it, this is now happening for AC scenes too)

    Strangely enough the character's scale still works fine, but the layer seems to be completely ignored. What seems to be happening is that the character's layer will remain at whichever value it was before the scene got changed.

    Any clues?
  • Odd.  I will do some testing of my own.
  • Great, thanks Chris, let me know if you need me to provide any further info/content.
  • Any luck with this yet Chris?
  • Fixed for 1.43.
  • Yay! Thanks!
  • Is there an ETA on 1.43 btw Chris?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.