Search Unity

Resolved Player Input Components not working on Spawned PlayerObjects

Discussion in 'Netcode for GameObjects' started by alexennerfelt, Jun 25, 2022.

  1. alexennerfelt

    alexennerfelt

    Joined:
    Jan 7, 2017
    Posts:
    15
    Hi, I'm making a multiplayer game with Netcode and I decided to implement the InputSystem to make possible to use gamepads and mouse and keyboard.

    For some reason, the PlayerInput component is not listening for input when it is placed on the PlayerObject that is being instantiated and spawned from the Networkmanager.

    If I place the PlayerObject in the scene it moves just fine and recieves input.

    I check PlayerInput.inputIsActive and it is true.

    I tried:
    • Starting the scene with PlayerObject Instantiated already - Input Works
      -NetworkManager active or not makes no difference
    • Having the PlayerObject spawn from the NetworkManager - Input Doesn't work
    I'm sure it's an easy fix, but this is my first project for InputSystem and Netcode, so I'm in pretty deep water.
     
  2. alexennerfelt

    alexennerfelt

    Joined:
    Jan 7, 2017
    Posts:
    15
    I worked on it without the Networkmanager for a couple of hours, then I tried again and it worked. Boogieman out there :(
     
    jogly likes this.
  3. lord_danzig

    lord_danzig

    Joined:
    Oct 21, 2016
    Posts:
    2
    I believe there is a bug with the current InputSystem (Unity 2022.1.20f1 or lower) and netcode.

    Try this: use the new InputSystem, then run the game with netcode as host/client. You wont be able to move your Player prefab. But in the middle of the game go to your PlayerInput component and hit "Open Input Settings" - when there, try tweaking any value, such as Default deadzone Min (even if you dont use a controller) - make sure you do it while in Play Mode. Now see if you input works.

    That's what fixed it for me. So to get it working permanently using code, I just added this line: InputSystem.settings.defaultDeadzoneMax = 0.924f;

    to simulate changing that setting, and it works. not sure why.
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @alexennerfelt / @lord_danzig , from what you're saying the issue you're experiencing is probably the one solved in this thread . tl;dr: ensure your player prefab has no input script enabled by default, and that you enable it only on the local Player when it spawns. You also need to ensure that you're using the ClientNetworkTransform script displayed at the bottom of this page to make the server accept the player movement coming from the clients.

    Here's more info about how to do so with the Third Person Controller that comes with the standards assets.

    Does this help?
     
    Nubtown and Deleted User like this.
  5. Traiforce

    Traiforce

    Joined:
    Feb 6, 2017
    Posts:
    3
    yes it does help
     
    RikuTheFuffs likes this.
  6. ajargrey

    ajargrey

    Joined:
    Aug 13, 2019
    Posts:
    1
    Thanks a lot, this issue had been bugging me from several hours; this fixed it.