Legacy Documentation: Version 5.3
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorUtility.SaveFilePanel

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

Sumbission failed

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

Close

Cancel

public static function SaveFilePanel(title: string, directory: string, defaultName: string, extension: string): string;
public static string SaveFilePanel(string title, string directory, string defaultName, string extension);

Parameters

Description

Displays the "save file" dialog and returns the selected path name.

See Also: OpenFilePanel function.


Save File Panel.

no example available in JavaScript
using UnityEngine;
using UnityEditor;
using System.IO;

public class SaveFilePanelExample : EditorWindow { [MenuItem( "Example/Save Texture" )] static void Apply( ) { Texture2D texture = Selection.activeObject as Texture2D; if( texture == null ) { EditorUtility.DisplayDialog( "Select Texture", "You must select a texture first!", "OK" ); return; }

string path = EditorUtility.SaveFilePanel( "Save png", "", texture.name + ".png", "png" ); if( path.Length != 0 ) { // Convert the texture to a format compatible with EncodeToPNG if( texture.format != TextureFormat.ARGB32 && texture.format != TextureFormat.RGB24 ) { Texture2D newTexture = new Texture2D( texture.width, texture.height ); newTexture.SetPixels( texture.GetPixels( 0 ), 0 ); texture = newTexture; }

byte[] pngData = texture.EncodeToPNG( ); if( pngData != null ) File.WriteAllBytes( path, pngData ); } }

}