Hi,
I’m currently creating an interaction system in C++ and am having trouble making the outline only show on the client that can interact with the object.
My code looks like this:
CPP
void AHiderCharacter::Tick(float DeltaTime)
{
HidePropOutline();
LastProp = nullptr;
FHitResult HitResult;
bool bDidHit = GetPropInView(HitResult);
if (bDidHit)
{
UStaticMeshComponent* Component = Cast<UStaticMeshComponent>(HitResult.GetComponent());
LastProp = Component;
ShowPropOutline();
}
}
// ...
bool AHiderCharacter::GetPropInView(FHitResult& OutHitResult) const
{
FVector Start = CameraBoomComponent->GetComponentLocation();
FVector End = Start + (DetectPropDistance * CameraBoomComponent->GetForwardVector());
FCollisionShape Sphere = FCollisionShape::MakeSphere(DetectPropRadius);
return GetWorld()->SweepSingleByChannel(
OutHitResult,
Start, End,
FQuat::Identity,
ECollisionChannel::ECC_GameTraceChannel2,
Sphere
);
}
void AHiderCharacter::ShowPropOutline_Implementation()
{
FString Name = GetActorNameOrLabel();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, Name);
if (IsValid(LastProp))
{
LastProp->SetCustomDepthStencilValue(1);
LastProp->SetRenderCustomDepth(true);
}
}
void AHiderCharacter::HidePropOutline_Implementation()
{
if (IsValid(LastProp))
{
LastProp->SetRenderCustomDepth(false);
}
}
H
// ...
UPROPERTY(VisibleAnywhere)
UCameraComponent* CameraComponent;
// ...
private:
UPROPERTY(EditAnywhere)
float DetectPropDistance = 300;
UPROPERTY(EditAnywhere)
float DetectPropRadius = 20;
UStaticMeshComponent* LastProp;
bool GetPropInView(FHitResult& OutHitResult) const;
UFUNCTION(Client, Reliable)
void ShowPropOutline();
UFUNCTION(Client, Reliable)
void HidePropOutline();
When this runs I get both characters in the scene printing their name to the screen even when only one of them is looking at an object that can be interacted with.