Can't find InputComponent (UE4.16.3)

29_be_urc
unreal-cpp

#1

Hey all, I’ve been stuck at this chapter for a while now trying to figure out why I can’t seem to access the InputComponent on BeginPlay.
I’ve uploaded the git diff of the source tree here this is the diff as of the last lectures commit (link)

Basically once I possess the pawn I get:

LogTemp:Error: DefaultPawn_BP_C_0 is missing input component
LogTemp:Warning: Physics handle found

When I look at the DefaultPawn_BP though I can clearly see that PawnInputComponent0 is listed along with the Grabber and PhysicsHandle.
I’m guessing UE is calling GetOwner()->FindComponentByClass<UInputComponent>(); before it initialised, but I’m surprised Ben didn’t cover it if that’s the case. Could something have changed in the newer UE4 version?

Any help would be much appreciated.
Thanks,
Mentar


#2

Tried the next commit and the problem is there aswell, looks like the Unreal change broke this part of the course :frowning:

For now I solved it by moving InputController assignment to the TickComponent member of the UGrabber and am checking if it’s exists, if not then I assign it there and then … this works… but feels sooo dirty :nauseated_face: :

/// Look for attached Input Component (only appears at run time)
	if (!InputComponent){
		InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();
		
		if (InputComponent)
		{
			UE_LOG(LogTemp, Warning, TEXT("Input component found"))
				/// Bind the input axis
				InputComponent->BindAction("Grab", IE_Pressed, this, &UGrabber::Grab);
		}
		else
		{
			UE_LOG(LogTemp, Error, TEXT("%s missing input component"), *GetOwner()->GetName())
		}
	}

#3

I have this problem too, but I searched and found that We can’t find the input component because it’s seems that we are trying to grab the input component before the character has been fully initialized, I don’t know how we can fix that, your solution works for me, but I think this is a paliative solution hahaha.

Edit: So when you run the game choosing the Viewport mode instead of Simulate mode the code works fine.


#4

Just ran into this going through the course and I found you can just grab the InputComponent member variable directly from the AActor without searching for it with FindComponentByClass which seems to work.

Ie. instead of
InputHandle = GetOwner()->FindComponentByClass<UInputComponent>();

try something like:

InputHandle = GetOwner()->InputComponent;


#5

I was having the same issue. For me it turned out that I needed to set the Auto Poses and Auto Receive Input in my default pawn BP. Once I have these set you can get the InputController as expected in BeginPlay.


#7

This worked for me, thanks!


#8

Bro i am having a similar problem but worse, When i try to run the game i can’t even see the PawnInputComponent0 on my DefaultPawn_BP. Can you help me???


#9

Bro i am having a similar problem but worse, When i try to run the game i can’t even see the PawnInputComponent0 on my DefaultPawn_BP. Can you help me???

@Rahul_Malik I’m having the same issue, using the latest unreal version, so maybe that is the issue? What version are you using?


#11

Hey! I am using ue4.20 and turns out that unreal doesn’t show up the input component anymore… although it’s actually there, so feel free to use it in ur code!!