How to get Boolean value from the new input system?

Hello
Could someone help me get a Boolean value when a button is pressed?
I’ve tried several types but it looks like they all return float

It all returns floats so you just gotta check the float itself.

if(InputAction.ReadValue<float>() > 0.5f)
//do stuff

For buttons it returns 1 for down and 0 for up I think. Though I’m not positive so test that. It’d be nice if they would give us a simpler bool option though. Especially for Button types because a float seems silly in this case to me. The solution I’m still using just has properties like Action.IsPressed that returns a bool. Of course we could write our own on top there but still…

3 Likes

I guess he asks due to something like Class InputSystemUIInputModule | Package Manager UI website .

I wondered too, I don’t see boolean as an option here Input Bindings | Input System | 1.0.2

Perhaps Input Bindings | Input System | 1.0.2 would need to be done currently.

Hello people.
I managed to reach the expected result as follows

First I configured the button action like this:

Then I just used the “triggered” method to check if the button was pressed

public static bool test = false;
if (PlayerActions.triggered)
{
    if (test)
    {
        test = false;
    }
    else
    {
        test = true;
    }
}

Thank you all for your help:)

7 Likes

Take my advice for what it is worth, but your code would be a bit cleaner if you did:

test = !test

Other than that, your information was very useful for my latest project.

2 Likes