MakeEditable
Makes a file open for editing in version control.
Read time 3 minutesLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
MakeEditable(string)
Makes a file open for editing in version control.
public static bool MakeEditable(string path)
Parameters
Project relative path to the file.
Returns
Type | Description |
|---|---|
| bool | |
Remarks
Your version control system may be configured to only allow a single person at a time to edit certain types of files in order to avoid merge conflicts that arise when multiple people edit the same file. In this case, you must 'open' that file for editing (also known as 'checking out') to ensure that you have permission to edit the file at this time. Use this function to make a file 'open for editing' in a version control system that supports it.
File paths that are outside of Unity project folder, or not under version controlled folders (for example, "Library" or "Temp"), are always considered editable. returns for them, and otherwise does nothing.
MakeEditabletrueFile paths that refer to non-local Package folders are always considered to be non-editable. returns for them.
MakeEditablefalseWhen no version control system is active, then file paths inside the project are all considered already editable. returns and otherwise does nothing.
MakeEditabletrueWhen using a version control system, for example Perforce Helix, triggers a "Checkout" operation on the files, unless they are already editable. For files that were not added to version control yet, MakeEditable will add them to version control.
MakeEditableIf you set up a pre-checkout callback, Unity calls it as part of . See Provider.PreCheckoutCallback for more details.
MakeEditableusing UnityEngine;using UnityEditor;public class ExampleScript : MonoBehaviour{ [MenuItem("Example/Checkout Selected Asset")] public static void MenuExample() { var path = AssetDatabase.GetAssetPath(Selection.activeObject); var ok = AssetDatabase.MakeEditable(path); if (!ok) Debug.LogError($"Could not make {path} editable"); }}
Additional Resources: AssetDatabase.IsOpenForEdit.
MakeEditable(string[], string, List<string>)
Makes a list of files open for editing in version control.
public static bool MakeEditable(string[] paths, string prompt = null, List<string> outNotEditablePaths = null)
Parameters
Specifies an array of file paths relative to the project root.
Dialog prompt to show to the user, if a version control operation needs to be done. If (default), no prompt is shown.
nullOutput list of file paths that could not be made editable.
Returns
Type | Description |
|---|---|
| bool | |
Remarks
A multi-file variant of , that can also optionally show a prompt to the user if a Checkout/Add version control operation needs to be done. If the user cancels the dialog, Unity does not make the files editable. If the Unity Editor is operating in batch mode, Unity does not show a dialog and acts as if the user accepted the dialog prompt.
MakeEditableIf you pass an List, this function fills it with file paths that Unity could make editable.
outNotEditablePathsusing System.Linq;using UnityEngine;using UnityEditor;public class ExampleScript : MonoBehaviour{ [MenuItem("Example/Checkout Selected Assets")] public static void MenuExample() { var guids = Selection.assetGUIDs; var paths = guids.Select(AssetDatabase.GUIDToAssetPath).ToArray(); var ok = AssetDatabase.MakeEditable(paths, "These files need to be checked out"); if (!ok) Debug.LogError("Could not make some files editable"); }}
Additional Resources: AssetDatabase.IsOpenForEdit.