UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Utility Systems / Folder Path System Completed

Utility Systems — UGTK

Folder Path System

Summary

The Folder Path System solves "let the user pick a folder" twice over: a [FolderPath] attribute that turns any string field into a text box with a browse button in the inspector, and an Mn_FolderPicker component that opens a real folder dialog at runtime — the native Windows browser in a standalone build, Unity's own panel in the editor — reporting the result through UnityEvents.

It is the piece you need for a kiosk that exports photos, a tool that writes a report, or any build that has to ask the operator where to save.


Content


Modules Dependencies

None. No UGTK reference. The runtime picker uses a P/Invoke into the Windows shell (SHBrowseForFolder), which is bundled with the module.


Setup

There is no GIF for this module: every meaningful action opens an operating-system folder dialog, which is outside Unity and would put the machine's folder tree in the documentation.


How To Use

The attribute

using UGTK.UtilitySystems.FolderPathSystem;

public class Exporter : MonoBehaviour
{
    [FolderPath] public string outputFolder;
}

The drawer renders a normal text field plus a button that opens EditorUtility.OpenFolderPanel starting from Application.dataPath, and writes back the absolute path. On a field that is not a string it draws a warning instead of the field — no silent failure.

The runtime component

folderPicker.PickFolder();          // 0 params: bind it straight to Button.onClick
folderPicker.SetFolder(path);       // set from code (same validation and events)
folderPicker.ClearFolder();         // empties it
string current = folderPicker.FolderPath;   // read-only property

Good to know:


Testing Scene

Open Debug/FolderPathScene.unity. It holds FolderPicker with Mn_FolderPicker — the component itself — and FolderPath Example, which shows the same value being consumed. Everything worth pressing is in the inspector's Editor Test Tools.

  1. Current folder shows the stored path and, under it, the answer that actually matters: whether the folder exists and is writable. A folder that exists but is read-only fails at save time, far away from the choice that caused it, so the check is here rather than there.
  2. Type a path into Path and press SetFolder(). With Create If Missing on, a folder that is not there yet is created, and the message flips to exists and is writable.
  3. Use persistentDataPath fills in Unity's own writable folder — the safe default on every platform.
  4. ClearFolder() forgets it.

PickFolder() opens the real Windows dialog and is the one control this scene cannot script: it blocks the editor until you answer it. It is also Windows-only — on other platforms the component says so and SetFolder is the way in.

One asymmetry worth knowing: SetFolder normalises the path and honours Create If Missing, exactly as a pick does, but it deliberately does not raise onFolderPicked. Restoring a saved preference at startup is not the user choosing a folder, and a listener that uploads or saves on that event would fire on every launch.


Technical Info

Path Content
Scripts/Attribute/FolderPathAttribute.cs Marker PropertyAttribute
Scripts/Attribute/FolderPathDrawer.cs PropertyDrawer: text field + button, with the string-type guard
Scripts/Mn_FolderPicker.cs Runtime component: editor/native dialog, validation, folder creation, UnityEvents and C# events. Contains the WindowsNativeFolderPicker P/Invoke wrapper
Prefabs/SelectFolderButton.prefab Button already wired to PickFolder()
Debug/Mn_FolderPathExample.cs Minimal example of the attribute
Debug/FolderPathScene.unity Test scene

Mn_FolderPicker API: PickFolder(), SetFolder(string), ClearFolder(), FolderPath, events onFolderPicked / onCancelled / onError and FolderPicked / Cancelled / Error.


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Depends on 1

Used by 0

  • No other module depends on it.

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 1 module in total.