- Home /
How do I check if a user does not select a file using the EditorUtility.OpenFilePanel
In my project I'm asking a user to select a png which is then used to build a mesh.
I am using the EditorUtility.OpenFilePanel so that the user can select a file, with a while loop checking if the filepath ends with .png. If it doesn't it prompts the user to select another file.
However i'd also like to check if the user closes the chose file window. Via debugging it appears that the returned filepath is simply "", however when checking this in the while loop it doesn't break the loop.
Is there a way to specifically check if the user has closed the window? Or am I just missing something simple...
this is the code I am referring too:
while (!terrainBlueprintFilepath.EndsWith(".png") || terrainBlueprintFilepath != "") { terrainBlueprintFilepath = UnityEditor.EditorUtility.OpenFilePanel ("Pick Terrain Blueprint", "", ""); }
if (terrainBlueprintFilepath == "")
{
}
else
{
Debug.Log ("thanks for selecting a png");
TerrainEditor currentTerrainEditor = FindObjectOfType<TerrainEditor> ();
currentTerrainEditor.buildImage1 (terrainBlueprintFilepath);
}
Sorry if I have failed to properly explain my problem, but hopefully you can get the idea...
Your answer
![](https://koobas.hobune.stream/wayback/20220612042533im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Multifiring functions c# 0 Answers
Check if input field is something based on if a text is something 1 Answer