Forum rules - please read before posting.

Weirdness with sorting layers when loading from another scene

2»

Comments

  • Ok no worries. Alternatively, since we need to roll out a review build for clients ASAP and currently we can't do that because of this bug, could we implement the fix locally for now if you can share what's required?
  • It's more than just a couple of lines.  Send me an email, and I'll reply to it with what you'll need.
  • Will do, thanks
  • edited March 2015
    Just upgraded from AC 1.42c to 1.43 and can't wait to test the new features, the changelog looks awesome!

    But I have some bad news: Since upgrading, the layers are broken for me:
    - I all sorting maps of all levels set to "Sorting Layer" (but tried out everything wit "Order in layer" as well)
    - player prefab "order in layer" is "5"
    - As soon the game starts, the player "order in layer" is set to "0"

    But it's not a real problem for my current project because I can set all backgrounds to negative values, my (NPC) characters to zero and all foreground things to positive values.
  • Is this your first time upgrading AC?  I think AC may revert your Layers unless you tell it now to when importing the new package.

    First of all, be sure to disable Edit-mode preview on your Follow Sorting Map component.  When your game starts, your character should be set to 0 (or whatever it's supposed to be according to your Sorting Map) unless Offset original order? is checked - in which case it'll be added on.

    If something's wrong, I'll fix it - but it's important to know what the real cause of this issue is first.  More detail and screenshots would be appreciated.
  • I'll try it out later today and keep you updated! Thanks!
  • No problem - also, the new 2D tutorial covers the correct way to handle sorting maps and the like.
  • So the sorting layers issue does seem to have gone away for me! Hurrah!

    However I am having an issue with hotspots in a certain scene not being functional once I load the scene from a different scene. 

    If I load the scene in the editor and just hit play it all works fine, however if I arrive at that scene organically through the flow of the game, hotspots seem to not work, in fact it looks like AC in general is in some sort of dormant/disabled state as the menus don't seem to come up either (inventory/pause menu)

    Any thoughts? I am not too sure how to debug this either... the hotspots do appear to be there in the scene view with all their interactions hooked up properly etc. As in there doesn't seem to be anything different in the state of the level in the case where it works compared to the case where it doesn't (obviously there is something different but it's not immediately obvious - to me at least)
  • Is your game in some kind of permanent cutscene?  Go to the bottom of the Settings Manger, and check List active ActionLists in Game window?.  That might shed some light.
  • Reviving this bad boy almost after a month (wow! goes to show how much time I get to work on my AC project these days).

    First of all apologies for not replying to your super handy suggestion re: the "List active ActionLists in Game Window?" option. I thought I did reply but it looks like I didn't! Oh well. Anyway, I turned that on and it's very useful. 

    It did help me to solve some cases where this was happening which ended up being because I had forgotten to tick the "Wait until finish" option before doing a level load.

    However there are still cases where I am getting this problem (both hotspots that should be active but aren't, specifically NPC hotspots, as well as sorting layer issues) and it doesn't seem to be related to any zombie cutscenes. Indeed the debug box says "Current game state: Normal", yet I still get the character rendering in front of objects that were probably correctly in front of it as well as no interaction options when I hover over characters.

    Help would be much appreciated as this is a blocking issue! Many thanks!
  • This is two separate issues, and I'm not sure how they relate.  Which versions of AC and Unity are you working with?

    NPCs will be clickable if the object with their Collider + Hotspot is on the Default layer.  Unity have recently changed the way they deal with rotating colliders, so it's unfortunately now advised to place these components on the Sprite child itself, rather than a 2D Character's root object.  Are you making use of any Remember scripts on the NPCs in question?

    When it comes to the sorting layers, try to determing the culprit by looking at the sorting order when it's working, and comparing it when it's not.  How much is it out by?
  • Right, thanks for the advice on how to debug... that definitely yielded some interesting / useful results.

    So what seems to be happening is that in the case where things are working properly (before a level load/reload - I say reload cause in some cases these problems happen even when I load the same level which I need to do in some cases for instance after playing a cutscene)


    a) The sorting map layers range from 1 to 5 and the character's order in layer respects that (so the character's sprite order in layer value ranges from 1 to 5 as well, as expected)

    b) NPCs' Layer is set to Default

    when things STOP working what I observe is:

    a) The character's order in layer seems to be offset by some value so it now ranges from 7 to 11 (which explains why it always renders on top of everything)

    b) The NPCs' Layer has magically switched to "Ignore Raycasting" (which explains why picking doesn't work)


    So... that helps with identifying the cause of the problem, the question is, how do I fix it?


    To answer your other questions:

    Unity Version: 4.6.4f1
    AC Version: 1.42c

    NPC structure: So for the NPCs in the offending scenes, all I've got is a pretty simple structure (as I don't need them to move around or do anything fancy) where I just have a gameobject with the following omponents on it:

    Transform
    Sprite Renderer
    NPC
    Remember NPC
    Hotspot
    Box Collider 2D

    Is this wrong? Should I be using more of a hierarchical structure where I put some of these in a parent gameobject and then I just have the sprite in the child?
  • For the sprite ordering - unless your character is made up of several "sub-sprites" that need to be kept in some kind of relative ordering, you should be able to get around this by unchecking "Keep offset" in the Follow Sorting Map component.

    2D Characters should always have their Sprite Renderer placed in a child object, to ensure that the sprite faces the camera even when the NPC turns.  However, thanks to Unity changing their mind about certain things with the more recent releases, you'll also need to move the Hotspot onto the child as well.  (Don't forget to assign the child as the NPC's "Sprite child" Transform).

    Your hierarchy should look like:

    Root (Transform, NPC, RememberNPC, Circle Collider 2D)
     - Sprite child (Transform, Sprite Renderer, Hotspot, Box Collider 2D, Remember Hotspot)
  • Ok... I think with your suggestions I've now fixed all my problems...

    Took ages to make all the NPC structure corrections! Guess I only have myself to blame for that, should have been a bit more vigilant with the whole RTFM business...


    Despite my RTFM fail I wonder if it's worth adding an NPC creation prefab to the Scene tab in the GameEditor inspector, especially since there are so many steps one needs to remember to get an NPC in the scene in the right way.


    Also, since the hotspot and the circle collider now need to be on different objects does that mean that when you need to switch off an NPC you need to do a Send Message: Turn Off to both gameobjects now?

    As always, thanks for the help Chris!
  • You should be able to get by with the Hotspot: Enable or Disable Action, instead of sending messages.  It's frustrating for me too that the workflow has to be changed, but we're all having to deal with the changes Unity makes.
  • Ah nice one, I was certain there must be an explicit action to do this but couldn't spot it for some reason (although it was right there)

    Yeah the joys of working on top of an ever changing ecosystem! Can't complain though, the benefits far outweigh the drawbacks :)
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.