Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted How to use PlayerInput for Multiple GameObjects (Not For Multiplayer)

Discussion in 'Input System' started by MegaTDog, May 21, 2020.

  1. MegaTDog

    MegaTDog

    Joined:
    Jun 30, 2019
    Posts:
    8
    Hi,

    How do I allocate the Player Input (Script) with an ActionMap to multiple gameObjects without the Player Input thinking its a second player and allocating a controller scheme?

    I'm trying to make a game where you interact with NPC's using the "ActionButton" in the ActionMap

    In the old input system it was as simple:
    * Creating an NPC class/Script
    * in the void update() statement just doing a if(Input.GetButtonDown("ActionButton")) {/*do Something such as dialog*/}

    In the new input system, if you attach the Player input to every NPC, it allocates a controller to each NPC making it impossible to call the void onActionButton() {/*do Something such as dialog*/}

    Any advice on how to do this would be great?

    Thanks
     
  2. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    I am new to Unity Input system myself.
    That's how the system works right it allocates the devices that have been connected and which is being used currently so u can switch between inputs at run time. Maybe you could create ur own NPC input script and always make it listen to Keyboard Control scheme.
     
  3. Ashfid

    Ashfid

    Joined:
    Jun 8, 2019
    Posts:
    5
    Have one playerinput for multiple players or how many you wanna control. I have this player who uses his drone, so I just switch actionmap to drone when I press "certain button"
     
  4. XsongyangX

    XsongyangX

    Joined:
    May 25, 2019
    Posts:
    3
    You can add more listeners to the related action events of your PlayerInput component. (Pluses in the image). Beware that the order of execution of listeners is not guaranteed, to my knowledge.
    upload_2020-5-29_17-51-34.png
     
  5. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    • Doesn't the player have to be near the NPC to start an interaction?
    • If the player has to interact with NPC why does NPC need PlayerInput?
    You can just use your action when NPC is near the player right, you just listen to the Action input and if there is an NPC nearby do your interaction.
    Another way to do it is, when an NPC is nearby, trigger an event and enable interaction ActionMap which will then allow the player to use the Actions for interaction action.

    I don't think you need inputs in an NPC for this.

    references
    https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/QuickStartGuide.html
     
unityunity