(Unity 2017.3.1f1, and AC 1.63.2 (although, see below))
I'm back doing 2d stuff again, and I've picked up one of the old AC projects I was working on before my recent foray into 3d territory
The project hadn't been touched for a month or so, so when I reloaded it I upgraded it to AC 1.63.2, as I like to keep AC up-to-date, and I've never had any major problems upgrading in the past
This time all went smoothly - until I played the game through a couple of times, which was when I noticed that (on occasion, although not with any obvious pattern), some of the animated sprite actors weren't sorted correctly. In other words, animated sprites that should have appeared in front of other animated sprites were appearing behind them, and vice versa. That happened in both the editor, and also in the compiled version
All my animated sprites have a top level container object, with NPC or Player, and Paths scripts, and a child object containing the SpriteRenderer, Animator and the FollowSortingMap scripts
Well, after a day or so head-scratching, and trying out various possible solutions, I went back to an old version of the project. Loaded that up, ran it, and... no problems. The animated sprites were all sorted correctly
Hmmm... So, a bit more head-scratching, and then finally I tried going back to the latest, upgraded, version, but with a reverted version of FollowSortingMap.cs (from AC 1.62.6), and... lo and behold, again no problems. The sprites were all sorted correctly
So, a bit more digging, and... There seem to be two changes in the most recent version of the script, one of which is an editor-only thing, and as the problem occurs in the compiled version of the game as well as in the editor, that can't be the culprit
Which only leaves the change at line 207 in SetOriginalDepth
The version which works for me is:
originalDepth = transform.parent.position - transform.parent.position;
(which looks a little odd, but I guess would simply set originalDepth to Vector3.zero ?)
The latest version which caused me problems is:
originalDepth = transform.position - transform.parent.position;
Anyway, I've left a note to myself not to upgrade that particular script for any future upgrades for the time being, and, as I say, I can't give firm details on ways to reliably replicate the issue, all I can say is that for me it WAS an issue, and it seemed worth reporting anyway, in case it's something blindingly obvious
Comments
> All NPCs have exactly the same structure as the one shown here. When I initially encountered the problem, I went through each Prefab and enforced that, even down to the order in which each Component appeared on each GameObject. Ditto for the Player characters (although, only the one shown here is actually used in this particular game)
> The Marker GameObject that only appears on NPCs is used to Pathfind the Player to the NPC during Cutscene conversations. Probably irrelevant to the problem at hand but I'm including it for completeness
> I only ever noticed the problem when a Player and an NPC were overlapping, i.e. not when two NPCs were overlapping. That may just be coincidence. I'm not sure that I've got any scenes in this game where multiple animated NPCs even appear in the same scene together
> Although I have static NPCs that exist in some scenes when the scene loads (and which don't exhibit any problem behaviour anyway), animated NPCs are always spawned into a scene using an Object/Add Action
> One thing I tried when the problem first manifested itself was to adjust the "Shared Layer Separation" value in the GameEngine Prefab from 0.001 to 0.01 (and I may possibly have tried larger values too). Needless to say, that didn't work
{
Debug.Log("Set depth of " + transform.parent.name + " to " + depth + ", OriginalDepth: " + originalDepth);
transform.position = transform.parent.position + originalDepth + (transform.forward * depth);
}
else
{
transform.position = originalDepth + (Vector3.forward * depth);
}
{
if (KickStarter.settingsManager == null)
{
return;
}
if (SceneSettings.IsTopDown ())
{
depthAxis = DepthAxis.Y;
}
else
{
depthAxis = DepthAxis.Z;
}
if (transform.parent)
{
// From most recent version 1.63.2 of AC (this exhibits overlap problem)
//originalDepth = transform.position - transform.parent.position;
// From earlier version 1.62.6 of AC (this works)
//originalDepth = transform.parent.position - transform.parent.position;
// Current setting (this too works)
originalDepth = Vector3.zero;
}
else
{
originalDepth = transform.position;
}
}