Don't understand input

Hi, I have a question!
i would like to know why the engine allows for us to continuously utilize the SetupInputComponent function throughout gameplay.

void UGrabber::BeginPlay()
{
Super::BeginPlay();
FindPhysicsHandleComponent();
SetupInputComponent();

}
I had a basic knowledge of C (for use with programming microcontrollers) prior to starting this course and my understanding was that after a function is called, it moves on sequentially to the next function in the main (in this case the BeginPlay) and once finished, it exits the function. Because of this, I would like to know why we can continuously press LShift and RMB to “grab” even though the begin play function is only called once when the game is started.

Thank you.
Elijah

Because SetupInputComponent() isn’t what’s calling the Grab function it only sets up the input component. It’s simply binding those mappings so it knows what functions to call when certain input events happens. It would be like a setter function rather than doing any of the event logic.

1 Like

Hello DanM…

Please tell me what returns this function?

what means round braces?
it returns function or something other?

As I know to return object syntax is something like:

const FHitResult UGrabberr::GetFirstPhysicsBodyInReachh()
{
FHitResult Hit;

return Hit;
}

That’s calling the default constructor for FHitResult and achieves the same thing you wrote.

and it returns the FHitResult object which we created in the function? I mean this object:

  FHitResult Hitt;
GetWorld()->LineTraceSingleByObjectType(
	OUT Hitt,
	PlayerViewPointLocationn,
	LineTraceEndd,
	FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
	TraceParameterss
);

This isn’t in the screenshot you showed me. I don’t know what you’re talking about.

sorry

const FHitResult UGrabberr::GetFirstPhysicsBodyInReachh()
{

FVector PlayerViewPointLocationn;
FRotator PlayerViewPointRotationn;

AActor* Ownerr;
Ownerr = GetOwner();
Ownerr->GetActorEyesViewPoint(
	OUT PlayerViewPointLocationn,
	OUT PlayerViewPointRotationn
);

FVector LineTraceEndd = PlayerViewPointLocationn + PlayerViewPointRotationn.Vector() * Reachh;

FCollisionQueryParams TraceParameterss(FName(TEXT("")), false, GetOwner());

FHitResult Hitt;
GetWorld()->LineTraceSingleByObjectType(
	OUT Hitt,
	PlayerViewPointLocationn,
	LineTraceEndd,
	FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
	TraceParameterss
);

AActor* ActorHitt = Hitt.GetActor();
if (ActorHitt)
{
	FString StringHitActor = ActorHitt->GetName();
	UE_LOG(LogTemp, Warning, TEXT("Line Trace: %s"), *StringHitActor)
}

return FHitResult();

}

it returns HItt object, isn’t it?

No. that function you have returns a default constructed FHitResult.

return FHitResult();

is the same as writing

FHitResult Temp;
return Temp;

You want to be returning Hitt not FHitResult()

1 Like

thank you now it’s clear :slight_smile:

Privacy & Terms