[SOLVED] Enter Play Mode Options Enabled leads to multiple code executions

Hey support,

using Unity 2021.3.10f1
using Unity Input System 1.4.1

So I noticed that whenever I have the play mode options enabled (meaning that reload domain and reload scene are disabled, just the Enter play Mode Options are checked in order to quickly enter the play mode)
my Input code behaves faulty:

For example:

public void OnProgressDialogue(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                Message.Raise(new ProgressDialogueEvent());
            }
        }

OnProgressDialogue gets called when I hit the spacebar.
Now this method will get called twice in this scenario, which means the event will get raised twice.

This does not happen with a build and also it does not happen when the EnterPlayModeOptions are disabled, than the method gets executed exactly as it should: once.

I’ve read like about two years ago that the Input System didnt yet support EnterPlayModeOptions, is this still the case? Or is there a another setting I need to enable to make it work with EnterPlayModeOptions?

Edit: This is the whole class I use:

public class DialogueInputBehaviour : MonoBehaviour,
                                          IUiInputBehaviour,
                                          MOHInputActions.IDialogueActions
    {
        private IGameInput gameInput;

        public void InitInputBehaviour(IGameInput input)
        {
            gameInput = input;
        }

        public void RegisterInputCallbacks()
        {
            gameInput.GameInputActions.Dialogue.SetCallbacks(this);
        }

        public void UpdateInputBehaviour()
        {
        }


        public void OnProgressDialogue(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                Message.Raise(new ProgressDialogueEvent());
            }
        }

        public void OnEnterMainMenu(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                Message.Raise(new OpenMainMenuEvent());
            }
        }

        public void DisposeInputBehaviour()
        {
            // Didnt work
            gameInput.GameInputActions.Dialogue.SetCallbacks(null);

            // Didnt work
            gameInput.GameInputActions.Dialogue.Disable();

            // Didnt work:
            gameInput.GameInputActions.Dialogue.ProgressDialogue.Dispose();
            gameInput.GameInputActions.Dialogue.EnterMainMenu.Dispose();
        }

I’ve been using Input system with Enter Play Mode options (domain and scene reload disabled) just fine.

What is this Message.Raise? Couldn’t find that this is Unity built-in. Is it possible this is using a static event handler behind the scenes? Just in case the Raise method duplicates the call, rather than OnProgressDialogue running twice.

Try setting a breakpoint and check the call stack, is it both coming from the exact same source for both initial and repeated calls?

Message.Raise is a method I wrote, but that is not the problem. OnProgressDialogue gets called multiple times, when I debug I land multiple times in the method and the if-condition also gets called multiple times

Just for the record, here is the whole class I use. @CodeSmile you made think about the fact that I maybe don’t correctly unsubscribe from the callbacks, but sadly that does also not work, this is my whole class:

public class DialogueInputBehaviour : MonoBehaviour,
                                          IUiInputBehaviour,
                                          MOHInputActions.IDialogueActions
    {
        private IGameInput gameInput;

        public void InitInputBehaviour(IGameInput input)
        {
            gameInput = input;
        }

        public void RegisterInputCallbacks()
        {
            gameInput.GameInputActions.Dialogue.SetCallbacks(this);
        }

        public void UpdateInputBehaviour()
        {
        }


        public void OnProgressDialogue(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                Message.Raise(new ProgressDialogueEvent());
            }
        }

        public void OnEnterMainMenu(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                Message.Raise(new OpenMainMenuEvent());
            }
        }

        public void DisposeInputBehaviour()
        {
            // Didnt work
            gameInput.GameInputActions.Dialogue.SetCallbacks(null);

            // Didnt work
            gameInput.GameInputActions.Dialogue.Disable();

            // Didnt work:
            gameInput.GameInputActions.Dialogue.ProgressDialogue.Dispose();
            gameInput.GameInputActions.Dialogue.EnterMainMenu.Dispose();
        }

DisposeInputBehaviour() gets called in the OnDisable method of another class, that same class also calls InitInputBehaviour and RegisterInputCallbacks in OnEnable and gets called correctly (debugged it) but neither of the options I tried in DisposeInputBehaviour seperately to unsubscribe from the callbacks did the trick.
When EnterPlayModeOptions are enabled InitInputBehaviour and RegisterInputCallbacks gets only called once while the callback OnProgressDialogue gets called multiple times for a reason.

Bump

Alrighty, I fixed it. The issue was indeed the way to unsubscribe. gameInput.GameInputActions.Dialogue.SetCallbacks(null) actually works, when I debugged it I looked into the wrong spot, the code executes just fine with EnterPlayModeOptions enabled now :slight_smile: