Forum rules - please read before posting.

Sorting map/render order issue in build

I am using this controller method: https://adventure-creator.fandom.com/wiki/2D_point_and_click_along_one_axis related to this thread: https://www.adventurecreator.org/forum/discussion/8130/limit-2d-movement-to-left-right

I don't know if the issue I'm having is specifically related to the controller method in question, which is why I created a new thread.

My problem is that since movement is fixed to the X axis, my NPCs will always be at the same Y position as my player character, but I need my player to be able to walk past the NPC while always being rendered on top, such that the NPC is always rendered behind the player.

To be sure of this I created two sorting maps with one area each, and assigned these maps to the player character and NPC respectively. The sorting map for the NPC has an area with its order set to 1, and the sorting map for the player character has an area with its order set to 2.

I'm not sure, however, if the order value of an area in a sorting map is only relative to other areas within that same sorting map? If so, how else can I make sure that two objects at the same Y position are always rendered in a certain order?

The strange thing is that it seems to be working as intended each time when I hit play within Unity, however when I create a build, sometimes they are rendered correctly, and sometimes the NPC will render on top of the player character.

This video shows the result within Unity and in the build:
https://www.loom.com/share/bffa92649a6f4f999cc450a1c2d99f9c

PS. In this particular scene the NPC does not graphically extend to the same Y position as the player, but that is only the sprite. The NPC is actually placed in the same Y position as the player character.

Comments

  • When two sprites are in the same position, it gets kind of random as to which one Unity will draw first.

    You can have a sprite's Order In Layer value be offset by a constant amount by first setting entering in that offset value into the Sprite Renderer component, and then checking Offset original Order? in the Follow Sorting Map component.

    See the 2D Demo game's Brain2D as an example - his shadow sprite has an original Order of -1 to ensure that it is always one-less than the main body sprite.

    If your characters do not change their size, or their sprite order values, though, there's no need to rely on a Sorting Map at all. This feature is only necessary if you want characters to change their appearance dynamically as they move around a scene.

  • Oh okay, I thought the sorting map was mandatory. But no, the characters will never need to change size.

    If not using a sorting map, how can I make sure, that the NPC is always behind the player character?
  • Configure the NPC's Sprite Renderer component's Order In Layer value to be lower than that of the Player's.

    This is how Unity's rendering system works - AC's FollowSortingMap component just sets these vaues dynamically.

  • Thank you, 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.