I’m following the UE5 course and I’m trying to draw the Debug Sphere at the End vector of the Grabber component. I’m using UE5.2 and because of that, I want to use the Enhanced Input System. Currently I implemented a AddOnScreenDebugMessage() functionality in CryptRaiderCharacter.cpp that triggers if the Grab action started.
The two functions in CryptRaiderCharacter.cpp:
void ACryptRaiderCharacter::Grabbed(const FInputActionValue& Value)
{
const bool Grabbed = Value.Get<bool>();
if(Grabbed){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Grabbed"));
}
}
void ACryptRaiderCharacter::Released(const FInputActionValue& Value)
{
const bool Released = Value.Get<bool>();
if (!Released) {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("Released"));
}
}
The code in SetupPlayerInputComponent():
void ACryptRaiderCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
// Set up action bindings
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent))
{
...
//Grabbing
EnhancedInputComponent->BindAction(GrabAction, ETriggerEvent::Started, this, &ACryptRaiderCharacter::Grabbed);
EnhancedInputComponent->BindAction(GrabAction, ETriggerEvent::Completed, this, &ACryptRaiderCharacter::Released);
}
}
The problem is that the Scene Component Grabber does all the job when it comes to drawing the debug line:
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
FVector Start = GetComponentLocation();
FVector End = Start + GetForwardVector() * MaxGrabDist;
DrawDebugLine(GetWorld(), Start, End, FColor::Red);
//DrawDebugSphere(GetWorld(), End, 10, 10, FColor::Blue, true, 5);
...
}
Since I only want to draw the Debug Sphere if I click on a button, how can I access
FVector End
from UGrabber.cpp in my CryptRaiderCharacter.cpp? Or is there a better way to do this?
I tried to implement the Input System in Grabber.h and Grabber.cpp but the build fails with the reason, that SetupPlayerInputComponent is not a member of USceneComponent.