Skip to content

fix: match tree order to unity hierarchy#151

Merged
hashiiiii merged 1 commit into
mainfrom
fix/hierarchy-order
Jul 15, 2026
Merged

fix: match tree order to unity hierarchy#151
hashiiiii merged 1 commit into
mainfrom
fix/hierarchy-order

Conversation

@hashiiiii

Copy link
Copy Markdown
Owner

Summary

Order the diff tree the way Unity's Hierarchy window does: siblings follow the parent Transform's m_Children array, and scene roots follow SceneRoots.m_Roots (or m_RootOrder for old scene formats) instead of YAML document order.

Motivation

Unity serializes YAML documents in an order unrelated (often exactly reversed) to the Hierarchy. core/src/tree.zig built the tree in document order, so the editor window, CLI, and extension all showed objects in the wrong order — e.g. the Playground scene fixture rendered Floor → Crate → Sun while the Hierarchy shows Sun → Crate → Floor. One fix in core corrects all three surfaces.

Closes #150

Changes

  • Reorder each sibling list to the parent Transform/RectTransform m_Children order; PrefabInstance children rank via their stripped root Transform (reusing ownerNodeIdOfTransform).
  • Reorder roots by SceneRoots.m_Roots (class 1660057539, after side preferred) when present, else stable-sort by m_RootOrder (PrefabInstance roots read it from m_Modifications); prefabs and .asset files fall through untouched.
  • Nodes absent from the after-side ordering data (removed objects) keep insertion order after the ranked ones.
  • Extract modificationValue from instanceName for reuse.
  • Add five ordering tests (m_Children siblings, SceneRoots roots, m_RootOrder fallback, instance-among-siblings, removed-child placement).

Testing

  • zig build test --summary all — 168/168 tests passed (the five new tests failed before the fix with reversed order, e.g. expected 2, found 3).
  • pnpm test (extension) — 187/187 passed.
  • dotnet test (editor DotNetTests~) — 34/34 passed.
  • CLI on real fixtures:
    • prefablens site/fixtures/{before,after}/Assets/Scenes/Playground.unity now prints roots Sun → Crate → Floor, matching SceneRoots.m_Roots (previously Floor → Crate → Sun).
    • Empty-vs-Robot.prefab diff now prints Robot → Arm → Sensor, matching the root Transform's m_Children (document order is Sensor → Arm).

@github-actions github-actions Bot added the core Core diff engine (Zig) label Jul 15, 2026
@hashiiiii
hashiiiii merged commit 8147669 into main Jul 15, 2026
13 checks passed
@hashiiiii
hashiiiii deleted the fix/hierarchy-order branch July 15, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core diff engine (Zig)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tree order does not match Unity Hierarchy (siblings and scene roots often appear reversed)

1 participant