@@ -53,6 +53,10 @@ internal static InputActionAsset GetOrCreate()
5353
5454 internal static InputActionAsset CreateNewActionAsset ( )
5555 {
56+ // Always clean out old actions asset and action references first before we add new
57+ DeleteActionAssetAndActionReferences ( ) ;
58+
59+ // Create new asset data
5660 var json = File . ReadAllText ( FileUtil . GetPhysicalPath ( s_DefaultAssetPath ) ) ;
5761
5862 var asset = ScriptableObject . CreateInstance < InputActionAsset > ( ) ;
@@ -87,7 +91,6 @@ internal static InputActionAsset CreateNewActionAsset()
8791 }
8892
8993 CreateInputActionReferences ( asset ) ;
90-
9194 AssetDatabase . SaveAssets ( ) ;
9295
9396 return asset ;
@@ -114,7 +117,7 @@ private static void CreateInputActionReferences(InputActionAsset asset)
114117 }
115118 }
116119
117- #if UNITY_2023_2_OR_NEWER
120+ #if UNITY_2023_2_OR_NEWER
118121 /// <summary>
119122 /// Checks if the default UI action map has been modified or removed, to let the user know if their changes will
120123 /// break the UI input at runtime, when using the UI Toolkit.
@@ -147,13 +150,44 @@ internal static void CheckForDefaultUIActionMapChanges()
147150 }
148151 }
149152
150- #endif
153+ #endif
154+ /// <summary>
155+ /// Reset project wide input actions asset
156+ /// </summary>
157+ internal static void ResetActionAsset ( )
158+ {
159+ CreateNewActionAsset ( ) ;
160+ }
161+
162+ /// <summary>
163+ /// Delete project wide input actions
164+ /// </summary>
165+ internal static void DeleteActionAssetAndActionReferences ( )
166+ {
167+ var objects = AssetDatabase . LoadAllAssetsAtPath ( s_AssetPath ) ;
168+ if ( objects != null )
169+ {
170+ // Handle deleting all InputActionAssets as older 1.8.0 pre release could create more than one project wide input asset in the file
171+ foreach ( var obj in objects )
172+ {
173+ if ( obj is InputActionReference )
174+ {
175+ var actionReference = obj as InputActionReference ;
176+ actionReference . Set ( null ) ;
177+ AssetDatabase . RemoveObjectFromAsset ( obj ) ;
178+ }
179+ else if ( obj is InputActionAsset )
180+ {
181+ AssetDatabase . RemoveObjectFromAsset ( obj ) ;
182+ }
183+ }
184+ }
185+ }
151186
152187 /// <summary>
153188 /// Updates the input action references in the asset by updating names, removing dangling references
154189 /// and adding new ones.
155190 /// </summary>
156- /// <param name="asset"></param>
157191 internal static void UpdateInputActionReferences ( )
158192 {
159193 var asset = GetOrCreate ( ) ;
@@ -195,6 +229,8 @@ internal static void UpdateInputActionReferences()
195229 }
196230 }
197231 }
232+
233+ AssetDatabase . SaveAssets ( ) ;
198234 }
199235 }
200236}
0 commit comments