Skip to content

Fix compile errors on Unity 6000.5 (CS0619) and 6000.6 (UAC1016) - #6

Open
lordborden wants to merge 2 commits into
radiatoryang:mainfrom
lordborden:fix/unity-6000.5-entityid
Open

Fix compile errors on Unity 6000.5 (CS0619) and 6000.6 (UAC1016)#6
lordborden wants to merge 2 commits into
radiatoryang:mainfrom
lordborden:fix/unity-6000.5-entityid

Conversation

@lordborden

@lordborden lordborden commented Jul 18, 2026

Copy link
Copy Markdown

Two independent compile errors block Scopa on current Unity releases. Both fixes are small and backward-compatible.


1. Unity 6000.5 — CS0619 in MapImporterEditor

Unity 6000.5 promotes two APIs from obsolete-warning to obsolete-as-error (CS0619):

  • SerializedProperty.objectReferenceInstanceIDValue
  • Object.GetInstanceID()

Fix: switch to the EntityId replacements Unity's own obsolete messages recommend, guarded so older editors keep the existing path.

#if UNITY_6000_5_OR_NEWER
    externalConfig.objectReferenceEntityIdValue = configAsset.GetEntityId();
#else
    externalConfig.objectReferenceInstanceIDValue = configAsset.GetInstanceID();
#endif

2. Unity 6000.6 — UAC1016 in GenericDictionary

Unity 6000.6 promotes its script-serialization rules to compiler diagnostics. GenericDictionary's two private lookup fields are marked [SerializeField, HideInInspector], which now fails the build outright:

Runtime/Utility/GenericDictionary.cs(22,39): error UAC1016: Field 'indexByKey' uses dictionary type
  'System.Collections.Generic.Dictionary<TKey, int>' whose key type 'TKey' is not serializable.
Runtime/Utility/GenericDictionary.cs(24,42): error UAC1016: Field 'dict' ... key type 'TKey' ...
Runtime/Utility/GenericDictionary.cs(24,42): error UAC1016: Field 'dict' ... value type 'TValue' ...

Fix: mark them [NonSerialized].

-        [SerializeField, HideInInspector]
+        [NonSerialized]
         private Dictionary<TKey, int> indexByKey = new Dictionary<TKey, int>();
-        [SerializeField, HideInInspector]
+        [NonSerialized]
         private Dictionary<TKey, TValue> dict = new Dictionary<TKey, TValue>();

Those attributes were never doing anything. Unity has no Dictionary<,> serialization support on any version, so no YAML was ever emitted for these two fields — only list is serialized, and OnAfterDeserialize rebuilds both lookups from it. The change just states that existing intent explicitly.


Compatibility

Neither fix changes behavior on the Unity versions Scopa already supports (package min 2022.3):

  • Fix 1 is behind #if UNITY_6000_5_OR_NEWER; older editors compile the original line.
  • Fix 2 needs no guard. Since the attributes were inert, serialized layout is unchanged on every Unity version — existing .asset / .prefab / .unity files keep round-tripping identically, and no reimport or migration is required.

Testing

Headless batchmode compiles of throwaway projects consuming this branch as a local package:

Editor Result
6000.5.4f1 exits 0, zero compile errors
6000.6.0f1 exits 0, zero compile errors

On 6000.6.0f1 I also ran the negative control: reverting only the GenericDictionary commit reproduces exactly the three UAC1016 errors above and fails the build, confirming that change is what clears them.

The 6000.6 build additionally emits two pre-existing UAC1002 warnings (ScopaEntityData's Sledge base classes Entity / MapObject lack [Serializable]). Those are warnings, not errors, they predate this PR, and fixing them means editing the vendored Sledge.Formats source — so I've deliberately left them out of scope here. Happy to open a separate PR if you'd like them addressed.

Unity 6000.5 marks SerializedProperty.objectReferenceInstanceIDValue and
Object.GetInstanceID() obsolete-as-error (CS0619), breaking compilation of
MapImporterEditor. Switch to the EntityId replacements the obsolete messages
recommend, guarded with UNITY_6000_5_OR_NEWER so the package still compiles
on the older Unity versions it supports (package min 2022.3).

Verified: a headless compile of a Unity 6000.5.4f1 project against this fork
exits 0 with zero compile errors.
Unity 6000.6 promotes its script-serialization rules to compiler
diagnostics. GenericDictionary's two private lookup fields are marked
[SerializeField, HideInInspector], which now trips UAC1016 as a hard
error and stops the package compiling:

  GenericDictionary.cs(22,39): error UAC1016: Field 'indexByKey' uses
    dictionary type 'Dictionary<TKey, int>' whose key type 'TKey' is
    not serializable.
  GenericDictionary.cs(24,42): error UAC1016: Field 'dict' ... (x2)

Those attributes were never doing anything: Unity has no Dictionary<,>
serialization support on any version, so no YAML was ever emitted for
these fields. Only 'list' is serialized, and OnAfterDeserialize rebuilds
both lookups from it. Mark them [NonSerialized] to state that intent and
keep the analyzer satisfied.

Because the attributes were inert, this is behavior-preserving on every
Unity version and needs no #if guard: serialized layout is unchanged, so
existing assets/prefabs/scenes keep round-tripping identically.

Verified against Unity 6000.6.0f1: a headless batchmode compile of a
project consuming this package exits 0 with zero errors. Reverting just
this commit in the same project reproduces exactly the three UAC1016
errors above, confirming this change is what clears them.
@lordborden lordborden changed the title Fix Unity 6000.5 compile error in MapImporterEditor (CS0619 obsolete-as-error) Fix compile errors on Unity 6000.5 (CS0619) and 6000.6 (UAC1016) Sep 7, 2026
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.

1 participant