using System; using System.Threading; using UnityEngine; public sealed class AsyncLifetimeProbe : MonoBehaviour { private async void Start() { CancellationToken lifetime = destroyCancellationToken; try { await Awaitable.WaitForSecondsAsync(1f, lifetime); if (this == null || !isActiveAndEnabled) return; Debug.Log("Completed while active", this); } catch (OperationCanceledException) { Debug.Log("Destroyed before completion"); } catch (Exception error) { Debug.LogException(error); } } }