unity 2019 input system and pun 2

Hello guys,

I hope someone can help with this issue. I am making a multiplayer game using unity 2019.4 and pun 2(photon network). I am trying to use the new input system but when I spawn players in the network, the input controls move and rotate all the players but with the old input system everything works.

In this script(see below) the commented lines are the lines I use while trying to use the new input system(no working) and the uncommented ones are the ones I use for old input system(working perfectly).

using Photon.Pun;
using UnityEngine;

public class CharacterInputManager : MonoBehaviourPun
{
    Transform myTrans;
    CharacterController controller;
    Animator myAnimator;
    float playerSpeed = 2.0f;
    float playerRotSpeed = 90.0f;

    // FOR NEW INPUT SYSTEM ONLY

    //GamepadControls controls;//New input system only
    //Vector2 moving;//New input system only
    //Vector2 rotating;//New input system only


    private void Awake()
    {
        myTrans = GetComponent<Transform>();
        controller = GetComponent<CharacterController>();
        myAnimator = GetComponent<Animator>();
    }

    // FOR NEW INPUT SYSTEM ONLY

    //private void OnEnable()//New input system only
    //{
    //    if (photonView.IsMine)
    //    {
    //        controls = new GamepadControls();//New input system only
    //        controls.Enable();
    //        controls.Player.PlayerMovement.performed += ctx => moving = ctx.ReadValue<Vector2>();
    //        controls.Player.PlayerMovement.canceled += ctx => moving = Vector2.zero;
    //        controls.Player.PlayerRotation.performed += ctx => rotating = ctx.ReadValue<Vector2>();
    //        controls.Player.PlayerRotation.canceled += ctx => rotating = Vector2.zero;
    //    }
    //}

    //private void OnDisable()//New input system only
    //{
    //    if (photonView.IsMine)
    //    {
    //        controls.Disable();
    //    }
    //}

    private void Update()
    {
        if (photonView.IsMine)
        {
            MovePlayer();
            RotatePlayer();
            Animate();
        }
    }

    void MovePlayer()
    {
        // FOR NEW INPUT SYSTEM ONLY

        //controller.Move(myTrans.forward * moving.y * Time.deltaTime * playerSpeed);//New Input system only
        //controller.Move(myTrans.right * moving.x * Time.deltaTime * playerSpeed);//New Input system only

        controller.Move(myTrans.forward * Input.GetAxisRaw("LeftVertical") * Time.deltaTime * playerSpeed);
        controller.Move(myTrans.right * Input.GetAxisRaw("LeftHorizontal") * Time.deltaTime * playerSpeed);
    }

    void RotatePlayer()
    {
        // FOR NEW INPUT SYSTEM ONLY

        //float rot;
        //if (moving.y < -0.1f)
        //{
        //    rot = -rotating.x;
        //}
        //else
        //{
        //    rot = rotating.x;
        //}
        //myTrans.Rotate(0.0f, rot * Time.deltaTime * playerRotSpeed, 0.0f);

        float rot;

        if (Input.GetAxisRaw("LeftVertical") < -0.1f)
        {
            rot = -Input.GetAxisRaw("RightHorizontal");
        }
        else
        {
            rot = Input.GetAxisRaw("RightHorizontal");
        }
        myTrans.Rotate(0.0f, rot * Time.deltaTime * playerRotSpeed, 0.0f);
    }

    void Animate()
    {
        ///FOR NEW INPUT SYSTEM ONLY

        //myAnimator.SetFloat("SurfaceSpeed", moving.y);
        //myAnimator.SetFloat("TurnSpeed", rotating.x);

        myAnimator.SetFloat("SurfaceSpeed", Input.GetAxisRaw("LeftVertical"));
        myAnimator.SetFloat("TurnSpeed", Input.GetAxisRaw("RightHorizontal"));
    }
}

Yeah, this has caught quite a few people unawares. The gist is that the multiplayer support that’s available with PlayerInput is not currently available with the generated C# wrappers. Requires some custom scripting.

I’ve posted some hopefully helpful tips here .

////EDIT: Adding support for control schemes and InputUser to the generated C# classes is on the list.

Rene-Damm,

Thank you for the response! I still don’t see what/how to change the generated script to fit the needs for a Photon Network multiplayer game in your tips. Could you be kind enough to explain in more details what to change or how to fix the problem. Photon has “photonView.IsMine” as a way to know if the player is the local player. Since my game is not a local multiplayer game but a networked one, and in my script above I only initiate the script containing the inputs if the player is local, how come my input script still controls gameobjects that don’t have the input script activated on them?

I would appreciate very much if you could explain a little more/better since I am not the brightest of people.

Regards,
Carlos