How does the program know when to check for Grab?

Hello,

so I was slightly confused after refactoring the code.
I see that a lot of functionality has been removed from being called every tick. In fact, everything was removed…

I understand how in BeginPlay(), which gets called only once, if I’m not mistaken, at the beginning of the game, we fetch the input component and bind the keys. But shouldn’t we now check every frame if the bound key is pressed? Or is that done internally somewhere? Because the tick function is pretty much empty now.

Handled by the engine by using the input binding

  1. The engine internally tracks what keyboard keys and mouse buttons have been pressed and released.
  2. The “input mappings” in Project Settings map these input keys and buttons to named actions. This is extremely useful, because you do not have to hard-code “left shift” or “right mouse button”, you can just refer to the “Grab” action. By default, that action is associated with the left shift and the right mouse button, but it is easy to change that in the Project Settings, and it even allows the players themselves to configure the mappings in some input configuration menu in runtime inside the game.
Input->BindAction(TEXT("Grab"), IE_Pressed, this, &UGrabber::Grab);
Input->BindAction(TEXT("Grab"), IE_Released, this, &UGrabber::Release);

Above, you register callbacks for the named action with the Input Component. Basically, the engine will internally let the Input Component know when the “Grab” action is pressed and released. And the BindAction() calls above tell the Input Component “hey, when the “Grab” action is pressed, I want you to call the UGrabber::Grab() function, and when the “Grab” action is released, I want you to call the UGrabber::Release() function”.

Privacy & Terms