Not signed in
Copyright © 2026 Unity Technologies
The NullReferenceException doesn't happen because of Awaitable.Cancel, it happens because you are setting the value after having awaited the Awaitable. As Awaitables are returned to the pool, it's not safe to used them after you have awaited them.
Steps to reproduce:
1. Open the attached user's project "awaitable-cancel-repro.zip"
2. Open the "Assets/Scenes/SampleScene.unity" and enter play mode
3. Observe the console window:
The AwaitableCancel MonoBehaviour on the "AwaitableTest - Cancel with Cancel() => NullReferenceException" GameObject produces a NullReferenceException
The AwaitableCancel MonoBehaviour on the "AwaitableTest - Cancel with token => works" GameObject doesn't produce an error
Actual result: error from using `Awaitable.Cancel`, but not if cancellation is done with a CancellationTokenSource instead
Expected result: no error from using `Awaitable.Cancel` to cancel an Awaitable
Reproducible with: 6000.0.78f1, 6000.3.19f1, 6000.5.2f1, 6000.6.0b2, 6000.7.0a1
Testing Environment: Windows 11
Not reproducible on: no other environment tested
Notes:
-The documentation https://docs.unity3d.com/ScriptReference/Awaitable.Cancel.html states:
Cancels the awaitable. If the awaitable is being awaited, the awaiter receives a System.OperationCanceledException
Note: some methods returning an Awaitable also accept a CancellationToken. Both cancelation models are equivalent
-Both cancelation models are not equivalient in this scenario
-error:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Awaitable`1[T].SetResultAndRaiseContinuation (T result) (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
UnityEngine.AwaitableCompletionSource`1[T].TrySetResult (T& value) (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
AwaitableCancel.Update () (at Assets/AwaitableCancel.cs:46)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <932fbe8ac5a946808aa5d7b95844e18c>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <254a04541d1c4a7b9e9c9e594cf72b4c>:0)
Sign in to see your voted issues