Skip to content

Commit a4ea6b6

Browse files
graham-huwstimkeoekcoh
authored
FIX: Give an appropriate error message if an asset went missing (ISX-1921) (#1881)
* FIX: Give an appropriate error message if an asset went missing (ISX-1921) * Fix format * Fix ArgumentException discovered during testing * Pre-existing issue and unrelated to original change; occurs when asset's .meta file deleted but not actual asset * If we don't have a working copy of the asset on reload, we need to create one. --------- Co-authored-by: Tim Keosababian <[email protected]> Co-authored-by: Håkan Sidenvall <[email protected]>
1 parent 3f4d780 commit a4ea6b6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/InputActionAssetManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ internal void SaveChangesToAsset()
198198
// If this is invoked after a domain reload, importAsset will resolve itself.
199199
// However, if the asset do not exist importedAsset will be null and we cannot complete the operation.
200200
if (importedAsset == null)
201-
throw new Exception("Unable to save changes. Associated asset do not exist.");
201+
throw new Exception("Unable to save changes. Associated asset does not exist.");
202202

203203
SaveAsset(path, m_AssetObjectForEditing.ToJson());
204204
SetDirty(false);

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,32 @@ private void CreateGUI() // Only domain reload
165165
// Therefore we recreate the state here using the fields which were saved.
166166
if (m_State.serializedObject == null)
167167
{
168+
InputActionAsset workingCopy = null;
168169
try
169170
{
170171
var assetPath = AssetDatabase.GUIDToAssetPath(m_AssetGUID);
171172
var asset = AssetDatabase.LoadAssetAtPath<InputActionAsset>(assetPath);
173+
174+
if (asset == null)
175+
throw new Exception($"Failed to load asset \"{assetPath}\". The file may have been deleted or moved.");
176+
172177
m_AssetJson = InputActionsEditorWindowUtils.ToJsonWithoutName(asset);
173-
m_State = new InputActionsEditorState(m_State, new SerializedObject(m_AssetObjectForEditing));
178+
179+
if (m_AssetObjectForEditing == null)
180+
{
181+
workingCopy = InputActionAssetManager.CreateWorkingCopy(asset);
182+
m_State = new InputActionsEditorState(m_State, new SerializedObject(workingCopy));
183+
m_AssetObjectForEditing = workingCopy;
184+
}
185+
else
186+
m_State = new InputActionsEditorState(m_State, new SerializedObject(m_AssetObjectForEditing));
174187
m_IsDirty = HasContentChanged();
175188
}
176189
catch (Exception e)
177190
{
178191
Debug.LogException(e);
192+
if (workingCopy != null)
193+
DestroyImmediate(workingCopy);
179194
Close();
180195
return;
181196
}
@@ -316,7 +331,7 @@ private void OnDestroy()
316331
if (m_AssetObjectForEditing != null)
317332
DestroyImmediate(m_AssetObjectForEditing);
318333

319-
m_View.DestroyView();
334+
m_View?.DestroyView();
320335
}
321336

322337
private void ReshowEditorWindowWithUnsavedChanges()

0 commit comments

Comments
 (0)