Why InputComponent is in beginplay() instead tickComponent()

Why the inputcomponent is used in beginplay() and how it’s working whenever we press a button since the beginplay() is called only once and acts like a tickcomponent(). But if I try to write that code in constructor the UE4 crashes. Can anybody explain me this? Thanks

To quote myself from the Q&A this morning.

This function does not call Grab or Release. It merely binds the Action “Grab” with the input event Pressed and Released with the member functions Grab and Release respectively.

This does not call either function.


What its doing is setitng a pointer to member function which will call Grab or release when the input event happens.

Take this code example

https://godbolt.org/z/5dN5-S

This is using pointer to non -member function to make it a bit easier.

Line 17 is effectively what is happening in that function, note if you comment out the rest of main there’s no output because One or Two were never called.

Lines 18 and 21 are what call the functions (through the function pointer).

Here’s a more complicated pointer to member function example

https://godbolt.org/z/J6sWEF

1 Like

Thanks a lot. With this example I got a better understanding of binding.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms