Why does the BindAction for Key Binding work in BeginPlay?

Hi, this is in the archived unreal course, lecture 90 (input binding) where ben shows us how to bind key strokes and inputs to functions.

so if u take a look in this snippet of code,

void UGrabber::BeginPlay()

	InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();
	if (InputComponent) {

		InputComponent->BindAction("Grab", EInputEvent::IE_Pressed, this, &UGrabber::Grab);
		InputComponent->BindAction("Grab", EInputEvent::IE_Released, this, &UGrabber::Release);

You’ll find that the input binding is happening in the BeginPlay() function that is only activated in the beginning of the game. But whenever I click the designated button it works without any problems by printing to the console (from the Grab & Release functions). WHY? Since BeginPlay is not a function that is constantly monitoring input every frame like the Tick function, how is it that this key Binding is working?

There are things that only need to be done once, not continually =)

It’s not calling the function it’s binding it to an event. So when that event happens that function will be called. The binding only needs to happen once.

Thank you :yum::yum:

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

Privacy & Terms