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...
Comments
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.
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.
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.
Also, what's should the background/player sprites actually be, and what are they instead when it doesn't work?
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)
- 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"
Any clues?