Sanity Check Please :)

Just wanted to check… is the reason for not being able to bind the input action directly to Gun because it effectively doesn’t exist (no memory address yet) because its being spawned at runtime?

(this is at around 04:20ish in the lecture)

Yes… but in a way also no. First you can test this by removing the input binding and in SetupPlayerInputComponent and adding this in BeginPlay after spawning the gun

if (InputComponent)
{
	InputComponent->BindAction(TEXT("Shoot"), EInputEvent::IE_Pressed, Gun, &AGun::PullTrigger);
}

So why is it also no? Because doing it the way it was done in the lecture sets you up for multiple guns that you can switch between. If you were to bind it directly then that is for that specific gun so would need to rebind it whenever you switch weapon.

3 Likes

Hi Dan, thanks for the reply.

I did actually try that code prior to your reply and noted that nothing happened, that was what made me wonder if it was due to the actor not being spawned yet, at the point of the binding etc.

The second part of your reply also makes perfect sense, thank you.

I consider my sanity checked :slight_smile:

2 Likes

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

Privacy & Terms