Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question How to use InputSystem on multiple objects?

Discussion in 'Input System' started by waffles14, Aug 14, 2022.

  1. waffles14

    waffles14

    Joined:
    Mar 8, 2018
    Posts:
    7
    I'm learning Unity (in 2d mode only for now), and I have set up a new InputSystem for my default Player object (the 'main character') and attached it accordingly. I've left it using the Send Messages behaviour if that matters.

    However, now I want to listen to player inputs on a completely different object (not UI). If I try listening to 'OnFire' or 'OnMove' in an object that doesn't have the Player Input component on it, nothing happens, which I'm not too surprised at. What I'm not sure about is, what is the best/proper way to make inputs be heard in a completely different object?
     
  2. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    451
  3. waffles14

    waffles14

    Joined:
    Mar 8, 2018
    Posts:
    7
    Thanks, I'll check that out!

    I did find another approach; I made a separate InputMap in the input settings, specifically for that object, and applied another Player Input component to it, selecting that particular map. Is that a valid approach? Or is it not a good idea to have multiple objects in a scene with Player Input components on them?
     
  4. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    451
    I have never used 2 PlayerInputs for the same input so I don't really know - however it sounds like a hacky solution if you ask me :D.
     
  5. Calamarik

    Calamarik

    Joined:
    Nov 6, 2020
    Posts:
    1
    I know it's an old topic BUT, i had the same problem and the solution I found is just to change the behavior of the player input to "broadcast messages " instead of send. With this you can access the "OnMove" method in the children of your Object.

    Hope it helps someone.
     
  6. unity_YMiEI4IDh7EkXg

    unity_YMiEI4IDh7EkXg

    Joined:
    Apr 3, 2022
    Posts:
    1
    Thank you!! This fixed my problem!
     
  7. Paul-Sinnett

    Paul-Sinnett

    Joined:
    Nov 12, 2010
    Posts:
    28
    Ryiah and Lawreyy like this.
  8. Lawreyy

    Lawreyy

    Joined:
    Mar 13, 2024
    Posts:
    2