How can I get the FHitResult from "OnLanded"?

I am trying to get the FHitResult Vector from when the player lands, but I am not sure how. I tried things like this:

void AFPSCharacter::OnLanded(FHitResult& Hit)
{
	disVec = Hit->Location();
}

But I always get an error saying that this is not possible. Sorry if this is a stupid question, but I am really stuck and would really appreciate if someone could help me with this problem.

What is the actual error you receive? I’ll assume you created your own character class that extends the ACharacter class, is this correct?

#Solution

void ACharacter::OnLanded(FHitResult& Hit)
{
    const FVector disVec = Hit.ImpactPoint;
}

use the . instead of the →

declare your variable locally, unless you really wanted to use a global var

use ImpactPoint, that is the point you are wanting

Rama

The question is actually awefully phrased and I appologize for that. I have made several attempts of fixing it, and the errors seem to end in the “headers”. This is the declaration of the function:

virtual void OnLanded(FHitResult& Hit);

And this the error I get: ‘void ACharacter::OnLanded(const FHitResult &)’ : no override available for virtual member function from base ‘ACharacter; function is hidden’. How am I able to fix this error?

Ok, try this.

In the header file, declare the function with OVERRIDE.

virtual void OnLanded(FHitResult& Hit) OVERRIDE;

Then, as Rama correctly said, use it in the source file like this:

void AFPSCharacter::OnLanded(FHitResult& Hit){
    // make sure the parent class still does its things
    Super::OnLanded(Hit);
    // get dat Vec
    const FVector disVec = Hit.ImpactPoint;
}

I have a feeling this, coupled with the correction that Rama mentioned, will fix it for you.

Okay so it turns out that I am still getting an error. Just to make sure, I am going to include this so that I can be certain that I have not done anything crucially wrong:

class AFPSCharacter : public ACharacter //this should allow it to work, right?

The error I am getting now is this:

‘AFPSCharacter::OnLanded’ : method with override specifier ‘override’ did not override any base class methods

Ah… I just found out why, I didn’t fully read the API. I’m sorry about this man.

Here is the link to the docs: Link

This line in particular:

UFUNCTION(BlueprintImplementableEvent)  // HERE! <====
virtual void OnLanded
(
    const FHitResult & Hit
)

This can only be used in Blueprint…

What I think might work in C++ is this:

virtual void Landed(const FHitResult& Hit)

Actually, I just tested this and it works fine. =)

Here is the full code:

AFPSCharacter.h

virtual void Landed(const FHitResult& Hit) OVERRIDE;

AFPSCharacter.cpp

void AFPSCharacter::Landed(const FHitResult& Hit){
	Super::Landed(Hit);
    const FVector disVec = Hit.ImpactPoint;

	if (GEngine){
		GEngine->AddOnScreenDebugMessage(-1, DEBUG_MSG_TIME, FColor::Blue, TEXT("LANDED"));
	}
}

There we go!

Edit:

I forgot the add the ImpactPoint.

Ahhhh so this is what that meant :DD Thank you, will check it out when I get home and mark the answer as correct if it works.

Okay awesome! It compiled. I was also not aware that you NEED to include the “const” in front of the variables. Thanks for your help dude, I learned a lot.