How to use InputSystem on multiple objects?

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?

Use Unity Events: Unity - Manual: UnityEvents
Alternatively you can use C# Actions or delegates.
Unity Events are more convenient if you want to setup the event-registration in the Inspector.

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?

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 :smile:.

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.

Thank you!! This fixed my problem!

This came up recently in a project review. My suggestion: GitHub - LSBUGPG/SinglePlayerMultipleObjects: example showing how to forward input message in new Unity input system

2 Likes

You made my week. Cheers!