Search code examples
c#unity-game-engine

Can't subscribe to onPlayerJoined or onPlayerLeft


I'm trying to set up multiplayer for a game I'm currently working on by using the Player Input and Player Input Manager components in Unity, but I'm having trouble with getting information from the onPlayerJoined and onPlayerLeft events. This is what my GameManager/PlayerInputManager looks like: Visual of my Player Input Manager

For the Notification Behavior, I've tried using Send Messages, but I can't acquire the PlayerInput that way, same for Invoke Unity Events, but when I try to use Invoke C Sharp Events, I receive this error: CS0123: No overload for 'OnPlayerJoined' matches delegate 'Action'

Here's the relevant code in my GameManager script.

void Start()
{
    PlayerInputManager.instance.JoinPlayer(0, -1, null);
    PlayerInputManager.instance.JoinPlayer(1, -1, null);
}

void OnEnable()
{
    // Throwing CS0123: No overload for 'OnPlayerJoined' matches delegate 'Action<PlayerInput>'
    //PlayerInputManager.instance.onPlayerJoined += OnPlayerJoined;
    //PlayerInputManager.instance.onPlayerLeft += OnPlayerLeft;
}

void OnDisable() 
{
    //PlayerInputManager.instance.onPlayerJoined -= OnPlayerJoined;
    //PlayerInputManager.instance.onPlayerLeft -= OnPlayerLeft;
}

public void OnPlayerJoined(PlayerInput playerInput)
{
    Debug.Log("A player has joined!");
    /*playerList.Add(playerInput);

    if (PlayerJoinedGame != null)
    {
        PlayerJoinedGame(playerInput);
    }*/
}

void OnPlayerLeft(PlayerInput playerInput)
{
    Debug.Log("A player left the game.");
}

Please help!


Solution

  • I had set my InputActions asset to be named PlayerInput. Changing the name solved the issue, thank you everyone!

    p.s. I tried to mark an answer but as all responses were comments I could not; thank you hijinxbassist