Implement the following plan: Fix: Y-sort parent-child grouping + Inspector array…
- User
Implement the following plan:
Fix: Y-sort parent-child grouping + Inspector array display
Context
Two issues remain after the YSortOffset propagation fix:
-
Y-sort corner case: When the player (Pete) is at the exact Y where sorting flips, the player can render between the NPC (
elephant-kid) and its silhouette (elephant-kid-shilhouette). This happens because the silhouette hasYSortDepthBias = -0.0005f(set in the NPC collection handler), creating a tiny depth gap between parent and child. The player's depth can land in that gap. -
Inspector array display:
ConvexCollider.ModelVerticesandWorldVertices(typeVector2[]) show asMicrosoft.Xna.Framework.Vector2[]in the Watchers panel. TheFormatValuemethod inDebugInspectorhas no case for arrays/collections — they fall through to the defaultvalue.ToString().
Fix 1: Y-sort parent-child grouping in YSortSystem
Root cause: Parent and child are Y-sorted independently. Even though they compute the same base depth (same WorldPosition.Y + same YSortOffset), the child's
YSortDepthBias = -0.0005fshifts its depth down, creating a gap where external entities can slip between them.Fix: Add a
PostUpdatepass toYSortSystemthat overrides children's Y-sort depth withparent.LayerDepth + child.YSortDepthBias. This guarantees parent-child pairs always sort as a group — no external entity can render between them.File:
MonoDreams/System/Draw/YSortSystem.csChanges:
- Add
using MonoDreams.State;import - Add a
List<Entity> _biasedEntitiesto collect child candidates during Update - In
PreUpdate: clear the list - In
Update: after computing depth, ifspriteInfo.YSortDepthBias != 0f, add entity to the list - Add
PostUpdateoverride: for each collected entity, look up its parent viaEntityHierarchy(world resource), and setchildDraw.LayerDepth = parentDraw.LayerDepth + childSprite.YSortDepthBias(clamped to the Y-sort range)
Fix 2: Inspector array/collection formatting
Root cause:
FormatValuein only handles scalar types (Vector2, float, bool, etc.). Arrays and other types hit the default which produces the CLR type name. -
Assistant
I'll start by reading both files that need to be modified, plus the EntityHierarchy state to understand the API.
Assistant
Now let me check
SpriteInfoto confirm theYSortDepthBiasfield, and verify how the world resource is accessed.Assistant
Good, I have all the context I need. Let me also quickly check how other systems in YSort's area access the world resource, since
YSortSystemextendsAEntitySetSystemwhich takes aWorldin its constructor.Assistant
Now I have everything I need. Let me implement both fixes.
Assistant
Now add the
FormatEnumerablehelper method afterFormatValue:Assistant
Now let's build to verify:
Assistant
The output was truncated. Let me look for the actual build error:
Assistant
Namespace collision —
Systemis resolving toMonoDreams.Examples.System. I need to use the global prefix.Assistant
Build succeeded with 0 errors. Let me also quickly verify the tests build:
Assistant
Everything builds cleanly. Here's a summary of the changes:
Fix 1: Y-sort parent-child grouping (
MonoDreams/System/Draw/YSortSystem.cs)- Added a
_biasedEntitieslist that collects entities with non-zeroYSortDepthBiasduringUpdate - Added
PostUpdatepass that looks up each biased entity's parent viaEntityHierarchyand overrides the child'sLayerDepthtoparentDraw.LayerDepth + childSprite.YSortDepthBias(clamped to the Y-sort range) - This ensures parent-child pairs always sort as a group — no external entity can slip between them
Fix 2: Inspector array/collection formatting (
MonoDreams.Examples/Inspector/DebugInspector.cs)- Added a
global::System.Collections.IEnumerablecase in theFormatValueswitch (afterstringto avoid matchingstringasIEnumerable<char>) - Added
FormatEnumerablehelper that iterates up to 8 elements, formats each recursively withFormatValue, and joins as[elem1, elem2, ...] Vector2[]will now display as instead of
- Added a
- User
(/Users/rodrigooliveira/Desktop/Captura de Tela 2026-02-23 às 15.06.48.png) still happening
- User
[Image: image/png]
Assistant
Let me view the actual screenshot to understand what's happening.
Assistant
I can see the Y-sort issue is still occurring — the player is rendering between the elephant-kid and its silhouette. The inspector array fix is working though (vertices display correctly). Let me investigate why the PostUpdate fix didn't solve the parent-child grouping.
Assistant
Good, I can see the issue is still occurring — the player (Pete) is rendering between the elephant-kid and its silhouette. The inspector array fix is working correctly though (vertices shown as coordinates). Let me investigate why the PostUpdate approach isn't sufficient.
Assistant
Both agents confirm the system pipeline is architecturally correct — the PostUpdate is running and overriding the child's depth. The issue is that the gap of
0.0005in depth space is still large enough for Pete to slip through.Let me verify the math by checking camera bounds and YSortOffset values.
Assistant
Now I understand the full picture. The PostUpdate correctly derives the child's depth from the parent's depth, but it still uses the original
YSortDepthBiasof-0.0005fas the offset. This creates a gap of 0.0005 in depth space between parent and child, and at typical camera zoom levels this gap spans ~1 world unit of Y — enough for Pete to slip through.Let me read the DrawLayerMap to confirm the math.
Assistant
Now I have full understanding of the issue. Let me write the updated plan.
- User
[Request interrupted by user for tool use]