Skip to content

Commit dbe216a

Browse files
committed
patch up PlayerInput editor to prevent from recreating internals all the time
1 parent bb6a72d commit dbe216a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInputEditor.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)