Forum rules - please read before posting.

NPC's childed sprites flicker when following sorting map

I have an NPC (parent) carrying sprites (children), they are all at sorting layer 6 and all using the default sorting layer.  This works well, allowing my player to walk behind it.  But when the NPC is walking backwards and forwards (up and down the screen) and effectively changing its sorting layer, the child sprites flicker like they are changing sorting layer at different times.

My NPC has the NPC script.
Child of NPC has animator, sprite renderer, box collider and follow sorting map script.

Follow Sorting Map
Follow default - TICKED
Offset original order - UNTICKED
Also affect children - TICKED
Edit-mode preview - TICKED

The NPC is an 8 frame animation consisting of 21kb frames, the child sprites are less than a kb each (pixelart game)

I am using 10 pixels per unit to bring my sprites more in-line with Unity units, this solves pathfinding etc. Doubt this has any impact, just wanted to give as much detail as possible to help troubleshoot.

Comments

  • Thanks for the detail, though what version of Unity are you using?

    Have you tried pausing the game to confirm what you suspect, i.e. that each sprite is moved to a new layer on different frames?  When Unity's Editor is paused, you can advance frame-by-frame - if you haven't already, use this to confirm that this is indeed the cause of the flickering effect.

    The component ought to be affecting each child renderer at exactly the same time, so I can't see how there'd be a delay between them - especially since the data is so small as you've said.

    From your description, I'm assuming the SortingMap affects the Sorting Layer.   As a test, try instead having it affect the Order In Layer, and using the Offset original order? checkbox to have the child sprites displaying in the correct order.  You'll need to have each area of your Sorting Map set on orders at intervals large enough (e.g. 0, 10, 20) for each child sprite to fit within it.  But again, this'll just be a test.
  • Im using Unity 5.3.5f1

    Currently using...
    Sorting Map
    Affect sprite's:  Order In Layer
    Affect Character scale?:  TICKED
    Affect Character speed?:  TICKED

    I have paused and gone frame by frame, and the Order in Layer stays constant on the parent and the children.

    I tried with and without 'Offset original Order?:' ticked.  It made no difference to this issue.
  • I'm confused now.  Your Sorting Map affects the Order In Layer, and not the Sorting Layer, but in your first post you described your NPCs sprites as changing their layer.  When the game is paused, what is the precise difference with the bad sprites when the flickering occurs vs the next frame that it doesn't?

    If you're changing the order instead, then you should definitiely have 'Offset original order?' checked - but you'll also need to give each sub-sprite a different sorting order (e.g. -1) to the base sprite.  When the "official" order changes to e.g. 10, these sub-sprites will take their original order into account (so -1 would then be 9).

    If all sprites are on exactly the same order/layer, then flickering will occur naturally because their's no definite order that they should be displayed in.
  • I think i need to re-look at my entire sorting setup.  I think i have got lost with it somewhere along the way, I do have a lot of little problems with my sorting/layers and resizing.  What are your recommended settings for a 2d game, using sorting maps rather than 3D for depth.  Need to be able to walk around NPCs and objects etc.  And ideally be able to have sub-sprites per NPC etc.
  • Sorting Maps are definitely the recommended way to go.  The 2D Demo is available to pick apart, and it makes use of a SM to have the player character move in front of and behind various objects.

    It also makes use of the "Offset original order" feature so that the shadow sub-sprite is always displayed underneat the main player sprite.  It may be a more simple example than your own case, but it's the same principle.
  • Right.  I fired up the 2d demo so I could compare.  And I seem to be using all the same settings other than offset original order so I turned this on.  No matter what I do, the child/sub sprites always change to match the NPC parent sprites sorting layer when I tick Also affect children. The demo shadow's sorting map is 5 and the Brain sprite 6.

    I don't understand how the demo sub sprite is set to 5.  I can disable Also affect children, change it, and when I tick also affect children it then changes the sub sprite (shadow) to 5.  What is telling the shadow to change to 5? and how can I apply similar to my sub sprites?
  • It may be easier to see what happens if you first place the Brain2D prefab into an empty scene, so that it's not affected by any Sorting Map.  The main sprite, "Sprite", has an initial Order In Layer value of 0, while the shadow sprite, "BrainShadow", has a value of -1.

    As both the Offset original Order? and Also affect children? options are checked, these initial values will be added onto what the Sorting Map dictates.  For example, when the Sorting Map wants to change them to 6, the main sprite is set to 6+0=6, while the shadow is set to 6+(-1)=5.

    This means that both sprites will be changed as they move around the scene, but they will always have the same relative order between them - so the shadow will always be displayed under the main sprite.
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.