2
\$\begingroup\$

I'm using the (new) "Input System" package and the "Player Input" component on my player prefab like this:

Player Input

public class Player : MonoBehaviour
{
    [UsedImplicitly]
    public void Fire(InputAction.CallbackContext context)
    {
        if (!context.started) return;
        Debug.Log($"Fire!");
    }
}

The odd thing is, this method is invoked twice with context.started == true. What am I missing here? Why is the method invoked twice?

A minimal working example to reproduce the behaviour can be found on GitHub.

EDIT

The player joins automatically through the "Player Input Manager":

Player Input Manager

\$\endgroup\$
2
  • \$\begingroup\$ Any chance you have more than one player in the scene? \$\endgroup\$ – Philipp May 4 at 12:06
  • \$\begingroup\$ No, it's just one player. The player is spawned automatically when I press any button. I use "Player Input Manager" to achieve this. Let me add another screenshot to the question. You can also checkout and start the example project I added to GitHub, if you like. \$\endgroup\$ – Tim Büthe May 4 at 12:53
0
\$\begingroup\$

I tried to reproduce this issue by creating a brand-new project with the Input System and using your sample code. Nothing changed, but I can definitely suggest a workaround for this.

While using the Player Input Manager led me to the same results as yours, just spawning the Player prefab via custom code (or adding it to the scene beforehand) worked just fine. The Fire() callback was being called once only when the mouse button was pressed, as expected. Pew pew!

According to the scripting API, the Player Input Manager «manages joining and leaving of players», and that's it. I think you can smoothly get rid of this component and write your own Player Manager, which deals with spawning your player prefab and toggling user input during cutscenes and stuff.


The behaviour you are experiencing is likely to be a bug. The new Input System is a handy alternative to the limited, built-in input manager, but it's still under development. You may report it to the Unity team as well.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks a lot liggiorgio! I will go ahead and report this. Let's see if they have an answer. Or even fix it, if it turns out to be indeed a bug in Input System. \$\endgroup\$ – Tim Büthe May 6 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.