Version: Unity 6.3 LTS (6000.3)
LanguageEnglish
  • C#

GameWindow.DisposeAsync

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public ValueTask DisposeAsync();

Returns

ValueTask A ValueTask that represents the asynchronous dispose operation.

Description

Asynchronously disposes of the window and releases its resources.

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.

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