File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed
Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -417,17 +417,21 @@ private void OnNotificationBehaviorChange()
417417 case PlayerNotifications . InvokeUnityEvents :
418418 {
419419 var playerInput = ( PlayerInput ) target ;
420- if ( playerInput . m_DeviceLostEvent == null )
421- playerInput . m_DeviceLostEvent = new PlayerInput . DeviceLostEvent ( ) ;
422- if ( playerInput . m_DeviceRegainedEvent == null )
423- playerInput . m_DeviceRegainedEvent = new PlayerInput . DeviceRegainedEvent ( ) ;
424- if ( playerInput . m_ControlsChangedEvent == null )
425- playerInput . m_ControlsChangedEvent = new PlayerInput . ControlsChangedEvent ( ) ;
426- serializedObject . Update ( ) ;
427-
428- // Force action refresh.
429- m_ActionAssetInitialized = false ;
430- Refresh ( ) ;
420+
421+ bool areEventsDirty = ( playerInput . m_DeviceLostEvent == null ) || ( playerInput . m_DeviceRegainedEvent == null ) || ( playerInput . m_ControlsChangedEvent == null ) ;
422+
423+ playerInput . m_DeviceLostEvent ??= new PlayerInput . DeviceLostEvent ( ) ;
424+ playerInput . m_DeviceRegainedEvent ??= new PlayerInput . DeviceRegainedEvent ( ) ;
425+ playerInput . m_ControlsChangedEvent ??= new PlayerInput . ControlsChangedEvent ( ) ;
426+
427+ if ( areEventsDirty )
428+ {
429+ serializedObject . Update ( ) ;
430+
431+ // Force action refresh.
432+ m_ActionAssetInitialized = false ;
433+ Refresh ( ) ;
434+ }
431435 break ;
432436 }
433437 }
You can’t perform that action at this time.
0 commit comments