Skip to content

Conversation

@skibitsky
Copy link
Member

Overview

This PR removes deprecated Unity and UI Toolkit APIs from AppKit to ensure compatibility with current and future Unity releases. The project has been upgraded to Unity 6.3 LTS.

Core Changes

UI Toolkit API Migration

  • Migrated 32 components from deprecated UXML factory pattern to modern attribute-based declarations
  • Affects all runtime components, views, and sample app UI elements
  • Leverages Unity's source generators for improved performance

Version Compatibility Layer

  • Created centralized compatibility utility for version-specific Unity APIs
  • Abstracts differences between Unity versions for event handling, text input, and input system
  • Future Unity upgrades will only require updates in one place

Project Updates

  • Updated CI/CD workflows to Unity 6.3 LTS
  • Updated documentation to reflect Unity 6.3 requirement

Impact

  • ✅ Removes all deprecated API warnings
  • ✅ Forward compatible with future Unity releases
  • ✅ Improved maintainability
  • ✅ No breaking changes to public APIs

@claude
Copy link

claude bot commented Dec 11, 2025

Claude finished @skibitsky's task in 2m 24s —— View job


Code Review Complete

Tasks

  • Review Unity version compatibility utility
  • Review sample app changes
  • Review CI/CD workflow changes
  • Review UI Toolkit UXML migration patterns
  • Check for security issues and external domains
  • Post final review

Issue 1: Duplicate using statement in ListItem.cs

File: src/Reown.AppKit.Unity/Runtime/Components/ListItem.cs:1-4

using System;
using Reown.AppKit.Unity.Utils;
using UnityEngine;
using UnityEngine.UIElements;
using Reown.AppKit.Unity.Utils;  // Duplicate

Reown.AppKit.Unity.Utils is imported twice.


Issue 2: Potential memory leak in RegisterCallbackOnce compatibility shim

File: src/Reown.AppKit.Unity/Runtime/Utils/UnityVersionCompat.cs:20-36

The RegisterCallbackOnce fallback implementation for Unity versions < 6.0 captures onceCallback in a closure. If the callback throws an exception before UnregisterCallback is called, the event handler will remain registered permanently, causing a memory leak.

Recommendation: Wrap the callback invocation in try-finally:

onceCallback = evt =>
{
    try
    {
        callback(evt);
    }
    finally
    {
        element.UnregisterCallback(onceCallback);
    }
};

Issue 3: Missing null check in IsEscapeKeyPressed for New Input System

File: src/Reown.AppKit.Unity/Runtime/Utils/UnityVersionCompat.cs:59-70

public static bool IsEscapeKeyPressed()
{
#if ENABLE_INPUT_SYSTEM
    var keyboard = UnityEngine.InputSystem.Keyboard.current;
    return keyboard != null && keyboard.escapeKey.wasPressedThisFrame;

While the null check for keyboard exists, if keyboard is not null but escapeKey is null (unusual but theoretically possible in certain Unity configurations), this could throw a NullReferenceException.

Recommendation: Add defensive null check for escapeKey:

return keyboard != null && keyboard.escapeKey?.wasPressedThisFrame == true;

Issue 4: SetPlaceholder is no-op on Unity < 6.0 without user feedback

File: src/Reown.AppKit.Unity/Runtime/Utils/UnityVersionCompat.cs:44-52

The SetPlaceholder method silently does nothing on Unity versions before 6.0. This could confuse users who expect placeholder text to appear.

Recommendation: Add a compile-time warning or runtime debug log to inform developers that the feature is unavailable:

#else
    // Placeholder API not available in Unity versions before 6.0
    Debug.LogWarning($"TextField placeholder not supported in Unity {Application.unityVersion}. Upgrade to Unity 6+ for placeholder support.");
#endif

Issue 5: Trailing empty line in NetworkButton.cs

File: src/Reown.AppKit.Unity/Runtime/Components/NetworkButton.cs:89-91

UnityVersionCompat.RegisterCallbackOnce<GeometryChangedEvent>(this, _ => UpdateNetworkButton(AppKit.NetworkController.ActiveChain));
            

Clickable = new Clickable(() => AppKit.OpenModal(ViewType.NetworkSearch));

Double empty line (line 90-91) - inconsistent formatting.


Issue 6: Missing using directive for UnityEngine.InputSystem

File: src/Reown.AppKit.Unity/Runtime/Utils/UnityVersionCompat.cs:1-2

The file references UnityEngine.InputSystem.Keyboard.current but doesn't include the using directive. While the fully qualified name works, it's inconsistent with the rest of the codebase style.

Recommendation: Add conditional using directive:

#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif

Then use Keyboard.current instead of UnityEngine.InputSystem.Keyboard.current.


@sonarqubecloud
Copy link

@skibitsky
Copy link
Member Author

Waiting for game-ci/docker#271 to release Unity 6.3 LTS images to fix our CI

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.

2 participants