Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


DisposeAsync()

Asynchronously disposes of the window and releases its resources.
Read time 1 minuteLast updated 15 days ago

Definition

public ValueTask DisposeAsync()

Returns

Type

Description

ValueTaskA 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
DisposeAsync
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.
The 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."); }}