Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question 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:
    10
    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:
    10
    I worked on it without the Networkmanager for a couple of hours, then I tried again and it worked. Boogieman out there :(
     
    LeechFarm 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:
    105
    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?