Skip to content

Conversation

@Bli-AIk
Copy link

@Bli-AIk Bli-AIk commented Aug 23, 2025

  • Please check if the pull request fulfills these requirements
  • Tests for the changes have been added (for bug fixes / features)
    • Does it pass all existing unit tests without modification?
      • If not, what did you change?
      • If you altered it significantly, what coverage issue did you fix?
  • Docs have been added / updated (for bug fixes / features)
  • CHANGELOG.md has been updated to describe this change
  • What kind of change does this pull request introduce?
  • Bug Fix
  • Feature
  • Something else
  • What is the current behavior?

Library requires Unity 2022.2+ due to use of three new APIs (Application.exitCancellationToken, MonoBehaviour.destroyCancellationToken, Editor.DiscardChanges).

Users on older Unity versions cannot use the library without modifications.

  • What is the new behavior (if this is a feature change)?

This PR adds backward compatibility for Unity 2021+ by providing polyfill implementations for three APIs, using conditional compilation to select the appropriate implementation based on the Unity version:

  • Add ApplicationExitCompat.cs to provide a fallback exitCancellationToken for Unity versions older than 2022.2. On Unity 2022.2 or newer, the official Application.exitCancellationToken is used.
  • Update YarnProjectImporterEditor.cs to call Editor.DiscardChanges() on Unity 2022.2 or newer, and fall back to the older ResetValues() method on earlier editor versions.
  • Add MonoBehaviourExtensions.GetDestroyCancellationToken(this MonoBehaviour) as a compatibility extension: On Unity 2022.2 or newer it returns mb.destroyCancellationToken; on older versions it attaches (or reuses) an internal DestroyTokenNotifier component to hold a CancellationTokenSource that is cancelled in OnDestroy(), and returns that token.

This allows the library to be used on older Unity versions without requiring an upgrade, while preserving the behavior on newer Unity versions.

  • Does this pull request introduce a breaking change?

Nope. This change is fully backward-compatible and does not alter behavior for users on Unity 2022+.

  • Other information:
    This PR allows users on Unity 2021 to use the latest Yarn Spinner 3.0, which I think is a good thing.
    I did my best to provide polyfills for the three new APIs, but I’m not claiming it’s perfect.
    I’d really appreciate any feedback—if anything could be improved or done differently, feel free to suggest or adjust.
    The goal is just to help more users enjoy the library across different Unity versions.

…hanges)

Add a small compatibility layer and apply targeted fixes so the project can run on older Unity versions without forcing an engine upgrade.

- Add `ApplicationExitCompat.cs` to expose an `exitCancellationToken`-like token on Unity versions that don't provide `Application.exitCancellationToken`, and update usages to go through the compatibility entry point.
- Add conditional compilation in `YarnProjectImporterEditor.cs` to call `Editor.DiscardChanges()` on `UNITY_2022_2_OR_NEWER` and fall back to the older `ResetValues()` name on earlier editor versions.
- Add MonoBehaviourExtensions.GetDestroyCancellationToken(this MonoBehaviour) as a compatibility extension: On UNITY_2022_2_OR_NEWER it returns mb.destroyCancellationToken; On older Unity it attaches (or reuses) an internal DestroyTokenNotifier component on the GameObject that holds a CancellationTokenSource which is cancelled/disposed in OnDestroy(), and returns that token.

Rationale: these three changes are purely compatibility/backport work — they avoid forcing users to upgrade Unity for a few small API differences while preserving native API usage on newer Unity releases. No runtime behavior changes expected on supported newer versions.
… file

Extracted the editor-specific code from Runtime/Utility/EnsureInputModuleAvailable.cs into a new Editor/Utility/EnsureInputModuleAvailableEditor.cs file. Also updated meta files for various installer utilities with proper MonoImporter configurations.
@Bli-AIk
Copy link
Author

Bli-AIk commented Aug 24, 2025

I also modified EnsureInputModuleAvailable.cs. I simply separated the implementation of Editor and runtime code that was originally written in the same file by adding Editor/Utility/EnsureInputModuleAvailableEditor.cs

The reason is that the original implementation worked fine in Unity 2022+ but would cause issues in Unity 2021. Although the Unity editor wouldn't show any errors, the mounted scripts would still display compilation error prompts.

After the separation, I conducted tests in the built-in Dialogue System prefab using Unity 2021.3. Based on my current usage, everything works normally, and the new features of 3.0 are also available.

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