Hallo! I have Unreal 4.15 version and its my little notice. Is it ok to execute grab function in game start function? In my opinion its wrong and not works well as i expected. I think we need to use it in every frame to chek player input during whole gameplay time and its will work more correctly.
If you’re talking about what I think you are, no.
In the lecture, Ben’s assigning input for the Grab and Release
InputComponent->BindAction("Grab", IE_Pressed, this, &UGrabber::Grab);
InputComponent->BindAction("Grab", IE_Released, this, &UGrabber::Release);
What this is doing is telling InputComponent that whenever a “Grab” is pressed, call the Grab function, whenever it’s released, call the Release function. What ends up happening is behind the scenes, in code you never have to worry about, InputComponent is busy every frame processing all the input and deciding what is a move, what is a button press, etc, and when it detects that the player has IE_Pressed “Grab”, it calls your Grab function.
This saves you from having to write code in your own TickComponent(). No need to reinvent the wheel, InputComponent has it covered for you.
This has two VERY big advantages:
- You don’t have to code it. (Epic did the hard work for you!)
- It’s portable. You don’t have to worry about “how” Grab is pressed. On a tablet, you might have a button, it might be set to a GamePad controller, it might be the shift key. Within the Grabber code, you don’t have to care. Just say "when grab is pressed, execute Grabber::Grab();
Thank you!