Forum rules - please read before posting.

Sorting Order & Offsets for Children

edited March 2014 in Technical Q&A
Firstly, can I say that I love this tool. I can only find one area of complaint and I am going to post a work-around.

I am using the top-down 2D format.

image

This works great, except when my characters are made up of multiple sprites and animated in unity. The existing code changes all the orders to the same (which of cause causes issues).

The only work-around I can figure is putting a script on the child sprites to remember their original offsets and then calling on this script in the followsortingmap.cs file.


using UnityEngine;
using System.Collections;

public class InitalOffset : MonoBehaviour 
{

public int initalOffset;

// Use this for initialization
void Awake () 
{
if (GetComponent <SpriteRenderer>())
{
initalOffset = GetComponent <SpriteRenderer>().sortingOrder;
}
else
{
initalOffset = 0;
}
}

}

and then adding

public void GetOffset (GameObject obj)
{
//Debug.Log ("GetOffset called.");
if (obj.GetComponent <SpriteRenderer>())
{
if (obj.GetComponent <InitalOffset>())
{
offset = obj.GetComponent <InitalOffset>().initalOffset;
}
}
else
{
offset = 0;
}
}

to followsortingmap.cs.

You obviously need to call it in the renderers array, but it works.

I am wondering if there is consideration to include the ability to have multiple offsets in the script in the future?

-Armada / Dave

Comments

  • This feature should already be implemented - is it not?

    If your characters involve multiple sprites, just add a FollowSortingMap script to each sprite object.  If you check the "Offset original order" box, the initial offset will be maintained.

    If not, I'll look into it.  I appreciate you posting the workaround - but I'd like to know if the intended method isn't working for you.
  • Hey Chris,

    The answer is yes and no.

    If you get the original offset in the awake function, then this is fine, however each FollowSortingMap then goes and changes the order of its children (when it does not need to, as they have their own FollowSortingMap.cs component).

    It really needs to do one, or the other.

    I hope that makes sense.

  • Ah - good point.  I'll put an additional option to influence children or not - it won't retain the individual offsets of each child (to do that, just add a separate script to each child, as I said), but for simple scenarios it'll make things easier when they can all take the same value.
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.