Skip to content

Fix Unity 6000.5 compile error: migrate GetInstanceID to EntityId (#12)#13

Merged
wallstop merged 6 commits into
mainfrom
dev/wallstop/bug-fixes
Jul 6, 2026
Merged

Fix Unity 6000.5 compile error: migrate GetInstanceID to EntityId (#12)#13
wallstop merged 6 commits into
mainfrom
dev/wallstop/bug-fixes

Conversation

@wallstop

@wallstop wallstop commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #12 — Unity 6000.5 turns the obsolete Object.GetInstanceID() into a CS0619 compile error, which blocks the package from compiling on Unity 6000.5.x.

The single call site (Editor/DataVisualizer/DataVisualizer.cs, building a write-only UI Toolkit element name object-item-row-{id}) now routes through a small helper:

public static string GetObjectIdString(this Object obj)
{
#if UNITY_6000_4_OR_NEWER
    return EntityId.ToULong(obj.GetEntityId()).ToString(CultureInfo.InvariantCulture);
#else
    return obj.GetInstanceID().ToString(CultureInfo.InvariantCulture);
#endif
}

UnityEngine.EntityId / Object.GetEntityId() were introduced in Unity 6000.4 (the docs 404 on 6000.3), so the guard is UNITY_6000_4_OR_NEWER — note this differs from the UNITY_6000_3_OR_NEWER suggested in the issue. The guard also silences the pre-error deprecation warning on 6000.4. The value is only used to build a unique UI element name (grep-confirmed it is never read back), so the intulong change on 6000.4+ is inert.

Tests

Bootstraps the package's first EditMode test assembly (Tests/Editor/) with one behavior test asserting the id string is non-empty, stable across calls, distinct between objects, and numeric on both branches.

Verification (red → green)

Reproduced the bug and verified the fix via clean-slate CLI EditMode runs (deleted Library/ScriptAssemblies + Library/Bee, then -runTests):

Unity Branch Pristine (RED) After fix (GREEN)
6000.5.2f1 EntityId DataVisualizer.cs(5890,43): error CS0619 (only error) 0 errors, test Passed 1/1
6000.4.6f1 EntityId 0 errors, test Passed 1/1
2022.3.62f2 legacy GetInstanceID test-only CS1061 (proves test is non-vacuous) 0 errors, test Passed 1/1

Notes for reviewers

  • Why public? The helper needs to be reachable from the editor test assembly. InternalsVisibleTo is not honored for this editor→test assembly pair in Unity's compilation — verified across two clean compiles: extension-syntax access gave CS1061, static-syntax gave CS0122 'inaccessible due to its protection level', even though the compiled editor DLL provably contains the correct friend attribute. public on this editor-only utility is the robust choice; the rationale is captured in the class XML doc.
  • Version bumped 0.0.35-rc05.60.0.35.
  • Out of scope: the package also emits unrelated CS0618 warnings (UI Toolkit UxmlTraits/PreventDefault) on 6000.5 — non-blocking, a separate failure mode, left for a follow-up.

🤖 Generated with Claude Code


Note

Low Risk
Editor-only compile and warning fixes with behavior-preserving keyboard handling; object IDs remain session-scoped UI names and are not persisted.

Overview
Makes the package compile cleanly on Unity 6000.5+ and clears related CS0618 UIToolkit warnings on 2023.2+.

Unity 6000.4+ object IDs: UI row naming no longer calls obsolete GetInstanceID() directly. It uses new GetObjectIdString (EntityId on 6000.4+, legacy instance ID otherwise) for write-only element names.

UIToolkit deprecations: All KeyDownEvent handlers switch from PreventDefault() to PreventDefaultCompat (still calls PreventDefault only before Unity 2023.2; paired StopPropagation unchanged). HorizontalToggle drops unused UxmlFactory/UxmlTraits because the control is only constructed from C#.

Adds the first EditMode test assembly with coverage for GetObjectIdString, bumps package.json to 0.0.35, and adds internal PLAN/progress notes.

Reviewed by Cursor Bugbot for commit 7fa6bfb. Bugbot is set up for automated code reviews on this repo. Configure here.


Update — also clears Unity 2023.2+ CS0618 deprecation warnings (folded in)

Two deprecation-warning families that surface on Unity 2023.2+/6000.x are now fixed in this PR:

  • HorizontalToggle UxmlTraits (9 warnings): the deprecated UxmlFactory/UxmlTraits custom-control pair was removed. The element is only ever created via new HorizontalToggle() in C# and is referenced by no .uxml in the package, so its UXML/UI-Builder support was dead code. Code instantiation and default values are unchanged.
  • EventBase.PreventDefault() (15 sites): all are KeyDownEvent handlers already paired with StopPropagation() (which consumes the event; FocusController.IgnoreEvent no-ops on KeyDownEvent, so it doesn't apply). A new EventExtensions.PreventDefaultCompat calls PreventDefault() only under #if !UNITY_2023_2_OR_NEWER and is a no-op above that; all 15 sites route through it.

The UNITY_2023_2_OR_NEWER gate is exact — a baseline compile on 2023.2.13f1 confirmed PreventDefault starts warning at precisely that version.

Verification (0 errors, 0 CS0618, EditMode test passes) on the full matrix: 2023.2.13f1, 6000.5.2f1, 6000.4.6f1, 2022.3.62f2 (legacy path still calls PreventDefault there with no warning). On the live 6000.4.6f1 editor, the Data Visualizer window opens with a clean console (both HorizontalToggle instances build; migrated handlers run cleanly).

wallstop and others added 2 commits July 5, 2026 17:04
Unity 6000.5 makes the obsolete Object.GetInstanceID() a CS0619 compile
error. The sole call site (building a write-only UI Toolkit element name)
now routes through a small ObjectIdExtensions.GetObjectIdString helper that
uses Object.GetEntityId()/EntityId.ToULong on Unity 6000.4+ (where EntityId
was introduced) and falls back to GetInstanceID() on older editors.

Bootstraps the package's first EditMode test assembly. The helper is public
because InternalsVisibleTo is not honored for this editor/test assembly pair
in Unity (verified: internal access yields CS0122/CS1061 from the test
assembly even with a correct friend attribute in the compiled editor DLL).

Verified via clean CLI EditMode runs (0 compile errors, test passes) on
Unity 6000.5.2f1 and 6000.4.6f1 (EntityId branch) and 2022.3.62f2 (legacy
branch). Bumps package version to 0.0.35.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Working-notes per the repo's session conventions: PLAN.md tracks active
items; progress/session-001 records the red-green verification and the
InternalsVisibleTo investigation behind the public-helper decision.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the Unity 6000.5 compilation break caused by Object.GetInstanceID() becoming an error by introducing an editor-only helper that switches to EntityId on Unity 6000.4+ while preserving the legacy path for older Unity versions. Adds an EditMode test assembly to validate the helper’s behavior and bumps the package version to a stable release.

Changes:

  • Replace the GetInstanceID() UI element naming usage with GetObjectIdString() to avoid CS0619 on Unity 6000.5.
  • Add ObjectIdExtensions.GetObjectIdString() with UNITY_6000_4_OR_NEWER gating (EntityId vs legacy InstanceID).
  • Introduce a first Editor test assembly + NUnit test covering non-empty/stable/unique numeric IDs; bump package.json version.

Reviewed changes

Copilot reviewed 7 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Editor/DataVisualizer/DataVisualizer.cs Switches object-row element naming to use the new ID helper.
Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs Adds the GetObjectIdString() helper with Unity-version conditional behavior.
Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs.meta Unity asset metadata for the new extension file.
package.json Bumps package version to 0.0.35.
Tests.meta Unity asset metadata for the new Tests folder.
Tests/Editor.meta Unity asset metadata for the new Tests/Editor folder.
Tests/Editor/WallstopStudios.DataVisualizer.Tests.Editor.asmdef Defines the Editor test assembly and its references.
Tests/Editor/WallstopStudios.DataVisualizer.Tests.Editor.asmdef.meta Unity asset metadata for the new test asmdef.
Tests/Editor/ObjectIdExtensionsTests.cs Adds EditMode test verifying ID helper behavior across Unity branches.
Tests/Editor/ObjectIdExtensionsTests.cs.meta Unity asset metadata for the new test file.
PLAN.md Adds a tracked work item entry for Issue #12.
PLAN.md.meta Unity asset metadata for PLAN.md.
progress.meta Unity asset metadata for the new progress/ folder.
progress/session-001-issue-12-entityid-fix.md Adds a session log describing the investigation and fix.
progress/session-001-issue-12-entityid-fix.md.meta Unity asset metadata for the new session log.
Files not reviewed (8)
  • Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs.meta: Generated file
  • PLAN.md.meta: Generated file
  • Tests.meta: Generated file
  • Tests/Editor.meta: Generated file
  • Tests/Editor/ObjectIdExtensionsTests.cs.meta: Generated file
  • Tests/Editor/WallstopStudios.DataVisualizer.Tests.Editor.asmdef.meta: Generated file
  • progress.meta: Generated file
  • progress/session-001-issue-12-entityid-fix.md.meta: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +17 to +19
- Helper `internal static string GetObjectIdString(this Object obj)` in new `Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs` (testable; keeps `#if` out of the 6000-line `DataVisualizer.cs`). Name deliberately avoids "stable" — instance/entity IDs are per-session only.
- Test access via `[assembly: InternalsVisibleTo("WallstopStudios.DataVisualizer.Tests.Editor")]`, following the existing `Runtime/DataVisualizer/BaseDataObject.cs` precedent (no AssemblyInfo.cs).
- Bootstrap `Tests/Editor` (first tests in this package), modeled on the sibling `unity-helpers` package's test asmdef. Single behavior-focused test; no bloat.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5f1194b — the "Decisions" section now states the final public helper choice (the initial internal + InternalsVisibleTo plan was proven non-functional for this editor→test assembly pair, detailed in the Investigation section).

Addresses a Copilot review comment on PR #13: the Decisions bullets still
described the initial internal + InternalsVisibleTo plan, which the
Investigation section supersedes. Updated to state the final public helper.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 15 changed files in this pull request and generated no new comments.

Files not reviewed (8)
  • Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs.meta: Generated file
  • PLAN.md.meta: Generated file
  • Tests.meta: Generated file
  • Tests/Editor.meta: Generated file
  • Tests/Editor/ObjectIdExtensionsTests.cs.meta: Generated file
  • Tests/Editor/WallstopStudios.DataVisualizer.Tests.Editor.asmdef.meta: Generated file
  • progress.meta: Generated file
  • progress/session-001-issue-12-entityid-fix.md.meta: Generated file

wallstop and others added 2 commits July 5, 2026 17:50
…efault)

Two deprecation-warning families surfaced on Unity 2023.2+/6000.x:

- HorizontalToggle used the deprecated UxmlFactory/UxmlTraits custom-control
  system (9 warnings). The element is only ever created via `new
  HorizontalToggle()` in C# and is referenced by no .uxml in the package, so
  the UXML/UI-Builder support was dead code — removed. Code instantiation and
  its default values are unchanged.

- EventBase.PreventDefault() is obsolete on 2023.2+ (15 call sites). All are
  KeyDownEvent handlers already paired with StopPropagation(), which consumes
  the event (FocusController.IgnoreEvent no-ops on KeyDownEvent, so it does not
  apply here). Added EventExtensions.PreventDefaultCompat, which calls
  PreventDefault() only under #if !UNITY_2023_2_OR_NEWER and is a no-op above
  that, and routed all 15 sites through it.

The 2023.2 gate is exact: PreventDefault was verified (baseline compile on
2023.2.13f1) to start warning at exactly that version. Verified via clean CLI
EditMode runs (0 errors, 0 CS0618, test passes) on 2023.2.13f1, 6000.5.2f1,
6000.4.6f1, and 2022.3.62f2, and on the live 6000.4.6f1 editor the Data
Visualizer window opens with a clean console.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 20 changed files in this pull request and generated 1 comment.

Files not reviewed (10)
  • Editor/DataVisualizer/Extensions/EventExtensions.cs.meta: Generated file
  • Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs.meta: Generated file
  • PLAN.md.meta: Generated file
  • Tests.meta: Generated file
  • Tests/Editor.meta: Generated file
  • Tests/Editor/ObjectIdExtensionsTests.cs.meta: Generated file
  • Tests/Editor/WallstopStudios.DataVisualizer.Tests.Editor.asmdef.meta: Generated file
  • progress.meta: Generated file
  • progress/session-001-issue-12-entityid-fix.md.meta: Generated file
  • progress/session-002-uxml-preventdefault-deprecations.md.meta: Generated file

Comment thread Tests/Editor/ObjectIdExtensionsTests.cs
Addresses a Copilot review comment: the legacy GetInstanceID() branch returns
an int, so int.TryParse reflects the contract precisely (was long.TryParse).
Verified on 2022.3.62f2: test passes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 20 changed files in this pull request and generated no new comments.

Files not reviewed (10)
  • Editor/DataVisualizer/Extensions/EventExtensions.cs.meta: Generated file
  • Editor/DataVisualizer/Extensions/ObjectIdExtensions.cs.meta: Generated file
  • PLAN.md.meta: Generated file
  • Tests.meta: Generated file
  • Tests/Editor.meta: Generated file
  • Tests/Editor/ObjectIdExtensionsTests.cs.meta: Generated file
  • Tests/Editor/WallstopStudios.DataVisualizer.Tests.Editor.asmdef.meta: Generated file
  • progress.meta: Generated file
  • progress/session-001-issue-12-entityid-fix.md.meta: Generated file
  • progress/session-002-uxml-preventdefault-deprecations.md.meta: Generated file

@wallstop wallstop merged commit f97768c into main Jul 6, 2026
2 checks passed
wallstop added a commit that referenced this pull request Jul 6, 2026
…acts

- Resolve PLAN.md/PLAN.md.meta both-added conflict by untracking them
  (kept as local, gitignored working artifacts per .gitignore).
- Stop tracking progress/* and progress.meta (local-only session logs).
- All other paths auto-merged cleanly; EntityId migration intact
  (all ID usage routes through ObjectIdExtensions.GetObjectIdString).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unity 6000.5 compile error: DataVisualizer uses Object.GetInstanceID()

2 participants