0

I mean, if during runtime there’s a new binding to a certain inputAction, such as:

inputAction.performed += ctx => Function(ctx.ReadValue<float>());

And suppose that before this new binding the player was already holding this input to 1f, and continues after being bound. This new input binding knows nothing about this held value, because no change was made to the input, and so no callback was called.

This, however, is problematic. I would like previously held inputs to execute callbacks even though no change was made.

For now, the input gets eaten until a change is made.

Is there a way to configure this? Or the only alternative would be to code it manually?

10
  • 10000% untested but what if you made a local variable say "i" which had a value you wanted depending on some calculation or lookup table - whatever - and then yu do myfunc(i); it will remember the value of i
    – BugFinder
    Aug 19 at 19:49
  • @BugFinder what are you talking about?
    – GuillemVS
    Aug 19 at 19:52
  • clearly about as clear as your question if it didnt make sense then i got the wrong end of what exactly youre asking
    – BugFinder
    Aug 19 at 19:56
  • @BugFinder we're not understanding each other, the question is unclear? I'm talking about inputs getting eaten when no change is made and a new binding is bound. I edited the question.
    – GuillemVS
    Aug 19 at 20:22
  • What are you trying to achieve? I would like previously held inputs to execute callbacks even though no change was made. This is just a workaround that you thought of. But that is not your end goal. What do you want to do with it? What is your problem and what do you expect to happen? We constantly get posts of people wanting Unity to do something other than it's supposed to because they have "some" ideas or expectations, but often, a solution can be achieved in a simpler way, other then rewriting a whole module like the Input subsystem :) Let's be pragmatic.
    – TheNomad
    Aug 19 at 20:32

1 Answer 1

1

You can not simply change the way events work in c# .. what you want basically means: In the moment you attach the listener also make a poll check to the action state and if it is currently pressed/triggered then invoke the method immediately as well.

I think you can do this like e.g.

inputAction.performed += ctx => Function(ctx.ReadValue<float>());

if(inputAction.inProgress)
{
    Function(inputAction.ReadValue<float>());
}
4
  • Exactly what I wanted, except you either mistyped or misunderstood my question, but it's not triggered, but rather inProgress, due to it being an axis, not a button press, what gets eaten. I'm giving you the answer, but change this part if you will.
    – GuillemVS
    Aug 20 at 9:19
  • @GuillemVS you keep hanging on the "triggering" part. Triggering in code is not the same as a Unity trigger. Same as "firing". Or "invoking". Focus on the answer, trust us, we understand if you explain properly or answer questions, don't just hang on irrelevant things :) A listener is the best approach, rather than polling as that might imply abusing Update() by most.
    – TheNomad
    Aug 20 at 9:56
  • 1
    @TheNomad the property triggered, does not return true when player is holding, because I assume it only returns true when it's pressed in the frame in which is pressed. My desired condition is that of inProgress, this resolves my issue.
    – GuillemVS
    Aug 20 at 10:50
  • 1
    @GuillemVS only on the phone so didn't have the exact API at hand, indeed as you say isTriggered seems to be the equivalent to Input.GetKeyDown (only true in the first frame) while inProgress is more the equivalent to Input.GetKey (true continuously while pressed), adopted the answer
    – derHugo
    Aug 21 at 13:01

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.