@@ -80,9 +80,11 @@ public override void OnInspectorGUI()
8080 EditorGUI . BeginChangeCheck ( ) ;
8181 EditorGUILayout . PropertyField ( m_ActionsProperty ) ;
8282 var actionsWereChanged = false ;
83- if ( EditorGUI . EndChangeCheck ( ) || ! m_ActionAssetInitialized || CheckIfActionAssetChanged ( ) )
83+ var assetChanged = CheckIfActionAssetChanged ( ) ;
84+ // initialize the editor component if the asset has changed or if it has not been initialized yet
85+ if ( EditorGUI . EndChangeCheck ( ) || ! m_ActionAssetInitialized || assetChanged || m_ActionAssetInstanceID == 0 )
8486 {
85- OnActionAssetChange ( ) ;
87+ InitializeEditorComponent ( assetChanged ) ;
8688 actionsWereChanged = true ;
8789 }
8890
@@ -262,7 +264,8 @@ bool CheckIfActionAssetChanged()
262264 if ( m_ActionsProperty . objectReferenceValue != null )
263265 {
264266 var assetInstanceID = m_ActionsProperty . objectReferenceValue . GetInstanceID ( ) ;
265- bool result = assetInstanceID != m_ActionAssetInstanceID ;
267+ // if the m_ActionAssetInstanceID is 0 the PlayerInputEditor has not been initialized yet, but the asset did not change
268+ bool result = assetInstanceID != m_ActionAssetInstanceID && m_ActionAssetInstanceID != 0 ;
266269 m_ActionAssetInstanceID = ( int ) assetInstanceID ;
267270 return result ;
268271 }
@@ -439,19 +442,21 @@ private void OnNotificationBehaviorChange()
439442 m_NotificationBehaviorInitialized = true ;
440443 }
441444
442- private void OnActionAssetChange ( )
445+ private void InitializeEditorComponent ( bool assetChanged )
443446 {
444447 serializedObject . ApplyModifiedProperties ( ) ;
445448 m_ActionAssetInitialized = true ;
446449
447450 var playerInput = ( PlayerInput ) target ;
448451 var asset = ( InputActionAsset ) m_ActionsProperty . objectReferenceValue ;
452+
453+ if ( assetChanged )
454+ m_SelectedDefaultActionMap = - 1 ;
449455 if ( asset == null )
450456 {
451457 m_ControlSchemeOptions = null ;
452458 m_ActionMapOptions = null ;
453459 m_ActionNames = null ;
454- m_SelectedDefaultActionMap = - 1 ;
455460 m_SelectedDefaultControlScheme = - 1 ;
456461 m_InvalidDefaultControlSchemeName = null ;
457462 return ;
0 commit comments