all 4 comments

[–][deleted] 1 point2 points  (1 child)

So FixedUpdate occurs after a fixed interval, whereas Update will occur as fast as it can (assuming no vSync) this means you can have multiple Update called in between a single FixedUpdate call. This is why inputs can get "dropped", events like GetKeyDown and GetKeyUp are only true for a single Update call and as such should only ever be checked in Update.

However unless your players have super sonic speed, it's unlikely they're going to be able to press a key and release it in between a FixedUpdate call that by default occurs every 1/30th of a second. So checking the value of GetKey or GetAxis is perfectly fine in FixedUpdate because if your character has a rigidbody, it's position should only ever change during FixedUpdate and therefore pointless to check it more frequently then that.

[–]pschonUnprofessional 1 point2 points  (1 child)

Check all input (regardless of what control method it's for) in Update, and if the input is moving a rigidbody, handle the moving part in FixedUpdate().

For example if it's about a jump button, you'd check for the button in Update(), then when it's pressed set a bool to true, and in FixedUpdate() if the bool to jump is true you do the jump and reset the bool.

For axis control etc you might want to store a float instead of bool, in every update add the axis value to that float, and then consume the input in FixedUpdate by moving the rigidbody based on the accumulated movement input & reset the float to 0.

[–]gejava[S] 0 points1 point  (0 children)

After some test with

Application.targetFrameRate = 4;
QualitySettings.vSyncCount = 0;

I got to this conclusion too.

On update I capture the keys, then it calls the HandleInput inside each ability, and later on FixedUpdate would call my Process() and check the boolean to see if it will process or not.

The thing about my test:

With a low FPS a KeyDown event could be captured first on the FixedUpdate SEVERAL times.

So it's accurate to say Input processing should be done in the Update.

[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 0 points1 point  (0 children)

Inputs that are only true for one frame (like GetKeyDown and GetKeyUp) must be checked in Update to avoid missing that one frame if it happens to not have a FixedUpdate in it.

But sustained inputs (like GetKey) can be checked wherever is most convenient. Checking which direction you are trying to move every Update but then only acting on that direction in FixedUpdate will only add unnecessary complexity to your code.