#Trying to use controller to change bool value.

1 messages ยท Page 1 of 1 (latest)

sturdy aspen
#

Hi! i'm following a tutorial to implement gamepad inputs but i'm struggling to implement this part:

        controls.Player.Fire.performed += ctx => fireWisp = true;
        controls.Player.Fire.canceled += ctx => fireWisp = false;
        controls.Player.Aim.performed += ctx => aim = ctx.ReadValue<Vector2>();
        controls.Player.Aim.canceled += ctx => aim = Vector2.zero;```
fireWisp doesnt seem to toggle into true while the Fire button is being pressed
zealous saddle
#

Wooh! Someone using the thread feature!

#

Maybe change "performed" to "started"? Performed is run on any frame where there is input, while started is used on the first when the button state changes from off to on (opposite canceled). @sturdy aspen

sturdy aspen
#

Hmm i tried changing it but still nothing, i tried printing fireWisp in update() and it's always false even if i set both started and canceled to true. maybe i'm declaring the variable wrong or something?

zealous saddle
#

Well, for a binary input, started is better, (but Aim.performed is still best for continuous input).

#

I know that doesn't solve things - just an observation.

sturdy aspen
#

yeah i havent even gotten to that part yet haha, struggling with the fire button

#

appreciate it :D

zealous saddle
#

Hmm, I don't usually use the input system in this way... does Aim.canceled work to reset aim = Vector2.zero?

sturdy aspen
#

i used ```c

    controls.Player.Movement.performed += ctx => move = ctx.ReadValue<Vector2>();
    controls.Player.Movement.canceled += ctx => move = Vector2.zero;``` and that seemed to work
zealous saddle
#

What is ctx? I've seen this before, but I don't recognize what class that is by convention.

sturdy aspen
zealous saddle
#

I'm just wondering where it's defined.

#

It's a context being passed to a lambda for sure, what what is being passed in? Can you link to the tutorial?

#

"Context" is a cool word for an object which is probably the first argument to a delegate somewhere.

sturdy aspen
#

Letโ€™s set up Gamepad controls using the new Unity Input System!

โ–บ SIGN UP FOR JASON'S UNITY COURSES: https://game.courses/mastery-course-brackeys-bonus/?ref=21

๐Ÿ‘•Check out our merch! https://lineofcode.io/

โ™ฅ Support Brackeys on Patreon: http://patreon.com/brackeys/

ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท...

โ–ถ Play video
zealous saddle
#

Okay thanks, I see what this is... just a moment.

#

controls.Player.Fire.performed += ctx => () => fireWisp = true; Can you try this for me?

sturdy aspen
#

i get this error:

zealous saddle
#
            InputActions.MenuBarControlsActions controls = new InputActions.MenuBarControlsActions();
            controls.OpenMenu.started += ctx => fireWisp = true;``` I just put this together in my project just to test what the object chain is and... I think your code makes complete sense.  Maybe the issue is elsewhere?
#

Do we know Fire is being triggered for sure?

sturdy aspen
#

i'll double check

zealous saddle
#

Are you checking the value of fireWisp in Update or something?

#

Especially since your Aim input is working, ctx in any case is referencing a void-returning function just the same, so it should be as simple as that.

sturdy aspen
#

Nice u were right

#

i missed some code and the button wasnt registering at all...

#

forgot this part

        controls.Player.Enable();
    }
        void OnDisable() {
        controls.Player.Disable();    
    } ```
now the first version of the code works
zealous saddle
#

ctx looks like such an oddly specific name, it threw me for a loop.

#

I immediately thought "controller" or smth.

sturdy aspen
#

haha, thanks a bunch! i really appreciate it :D