DisposeAsync()
Asynchronously disposes of the window and releases its resources.
Read time 1 minuteLast updated 15 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Windowing
- Assembly: UnityEngine.WindowingModule
public ValueTask DisposeAsync()
Returns
Type | Description |
|---|---|
| ValueTask | A ValueTask that represents the asynchronous dispose operation. |
Remarks
Use this method to dispose of a secondary window when you no longer need it. You cannot dispose of the main window. To close the main window, use Application.Quit instead.
The method clears all registered position and resolution change callbacks before it disposes of the window. After disposal, this GameWindow instance is no longer valid and you must not use it.
DisposeAsyncThe following code example demonstrates how to use this method to dispose of a secondary window.
Examples
using UnityEngine;using UnityEngine.Windowing;public class DisposeWindowExample : MonoBehaviour{ GameWindow secondaryWindow; void Start() { var settings = new GameWindowCreationSettings( title: "Secondary Window", width: 800, height: 600, position: new Vector2Int(0, 0), cameraDisplayIndex: 1, displayInfo: GameWindow.Main.GetDisplayInfo(), fullScreenMode: FullScreenMode.Windowed, resizable: false ); var op = GameWindowManager.Create(settings); op.completed += (AsyncOperation o) => { secondaryWindow = ((CreateWindowAsyncOperation)o).window; }; } async void DestroySecondaryWindow() { await secondaryWindow.DisposeAsync(); Debug.Log("Secondary window disposed."); }}