'Calling Differences Between Actor Components and Character Classes

We are currently implementing TraceinActorComponent and calling it into the Character class. However, HitResult is not returned properly and other functions are not working. What is the cause? I set Mesh collision to OverlapAll and turned on SimulationGenerates.

this is My cpp code ::

Character class :

AFPSCharacter::AFPSCharacter()
{
    // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    ActorComponent= CreateDefaultSubobject<UActorComponent>("ActorComponent");
    ActorComponent->Parent = this;
}

void AFPSCharacter::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    Movement();

    AActor* traceActor;
    traceActor = ActorComponent->Trace();
    if (traceActor)
    {
        GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Yellow, traceActor->GetName(), true);
    }
}

ActorComponent class :

AActor* UFPSCharacterGunComponent::Trace()
{
    bool isHit;
    FHitResult Hit;
    FVector Start, End;
    FCollisionQueryParams Params;

    Start = Parent->GetActorLocation();
    End = Parent->GetActorLocation() + Parent->GetActorForwardVector() * Range;

    isHit = Parent->GetWorld()->LineTraceSingleByObjectType(
        Hit, Start, End, ECollisionChannel::ECC_Visibility, Params
    );

    {
        FColor Color = isHit ? FColor::Red : FColor::Green;
        const float lifeTime = 1.f;
        DrawDebugLine(Parent->GetWorld(), Start, End, Color, false, lifeTime, 0, 5);
    }

    if (isHit)
    {
        HitActor = Cast<AActor>(Hit.GetActor());
        if (HitActor != nullptr)
        {
            return HitActor;
        }
    }
    return nullptr;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source