How is SendMessage behavior intended to work?

When I add a PlayerInput component, I can decide between messages and events. While the events worked as expected, given feedback for each occurrence, the SendMessage behavior throws me into an unexpected way.

I have a “Shoot” button (click, space, etc.) and I want it to fire while the key is held. When I instantiate the input class and call functions through the started and canceled callbacks, I am fine. When I use the events, I get an “InputAction.CallbackContext” instance and I can handle the phase there.

But when I use the SendMessage, it does not allow me to receive an “InputAction.CallbackContext”, it only gives me a value which tells nothing about the phase.

Can I know, using the SendMessage option, if the action is started, performed or canceled?

From I understand about the SendMessage it sends the data to InputValue

void OnFire(InputValue value)
{
       Random = value.Get<bool>();
}

random can be whatever you want
bool is whatever you action sends

I don’t think there is a way to do what you want with it

Thank you for your answer, Jonathen.

If someone wants to know how did I do solve the problem, I made a MonoBehaviour that handles the events manually and workaround the issue. I don’t know why the developers didn’t do the SendMessage part consistent with the behavior of the other parts, but I do imagine it has performance implications or another issue I do not realize now.

Anyway, for the small project I am playing, the workaround is pretty sufficient!

I have made it public here: Unity New Input System: workaround to receive actions via SendMessage for the three phases: started, performed, canceled. · GitHub

Of course, when someone is not lazy enough, he/she can use Unity events :slight_smile: But I had some fun developing it this way.

Let me know if there is a better way to achieve the same result.