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. Dismiss Notice

Resolved Control multiple Instance of an Object with only one "Player Input"-Component

Discussion in 'Input System' started by badschti, Apr 27, 2022.

  1. badschti

    badschti

    Joined:
    Nov 7, 2018
    Posts:
    6
    Hey all,
    i try to implement the new Input System so I can do persistent control rebinding. And I beating my head against the wall, it is just too complicated for me.
    My problem is the following:

    -> The Setup:
    I have ONE "Player Input"-Component with individual "Events". These "Events" are linked to different scripts. For example the Event "OnJump()" handles the jumping in the assigned "PlayerMovement"-Script, the "OnMenu()" handles the pause menu in the assigned "GameManager"-Script.​

    -> The Request:
    I need to duplicate my "Player"-Object multiple times and still need to be able to move EVERY instance/clone of my "Player"-Object with the same Input/Actionmap. So when I press "jump" EVERY player & player clone should jump not just the one where the script is linked to the "Player Input"-Event.​

    -> The Problem:
    But obviously the Event, i.e. "OnJump()", is just linked to ONLY ONE (the first) player. The rest will not get the Call and therefore don't jump.​

    -> The Solution, but really the second Problem:
    I can't just have multiple "Player Input"-Components because then the key binding doesn't work. The Script for the key rebinding is from the official sample.It just works when I use ONE "Player Input"-Component. I don't know why.​

    So what can i do? I would be really thankful for any response!
     
  2. badschti

    badschti

    Joined:
    Nov 7, 2018
    Posts:
    6
    Okay it seems like i have really strange behaviors:

    - I can not make "[SerializeField] public PlayerInputHandler playerInput;" visible in Inspector.
    Code (CSharp):
    1.     [SerializeField] public PlayerInputHandler playerInput;
    - I can't access it via code (i.e. "playerInput = GetComponent<PlayerInput>();").

    - I get errors when I have a "Player Input"-Component on my GameObject with "SendMessage" enabled:
    Code (CSharp):
    1.  
    2. public void OnJump(InputAction.CallbackContext context)
    3.     {
    4.         print("Jump");
    5.     }
    Error Message: "MissingMethodException: PlayerMovement.OnJump Due to: Attempted to access a missing member.

    I don't know why but I just can't help myself.
    I just need to handle the same Object with one PlayerInput-Component.
     
  3. badschti

    badschti

    Joined:
    Nov 7, 2018
    Posts:
    6
    Found a messy workaround. So i guess this Thread can be closed.
    Thanks :)
     
  4. grantengler

    grantengler

    Joined:
    Aug 15, 2022
    Posts:
    3
    What was your workaround? I've been having a similar issue.