Hello.
I have a projectile class and I need to let the CLIENTS know whenever an Explosive Projectile explodes.
To do this, I decided to use a RepNotify variable bExploded and a OnRep_Exploded function
Here is the code:
.H
UPROPERTY(Transient, ReplicatedUsing = OnRep_Exploded)
bool bExploded;
UFUNCTION()
void OnRep_Exploded();
.CPP
void AProjectile::Explode(const FHitResult& HitResult)
{
const FVector NudgedImpactLocation = HitResult.ImpactPoint + HitResult.ImpactNormal * 10.0f;
if (ExplosionParticle)
{
FTransform const SpawnTransform(HitResult.ImpactNormal.Rotation(), NudgedImpactLocation);
AExplosionEffect* const EffectActor = GetWorld()->SpawnActorDeferred<AExplosionEffect>(ExplosionParticle, SpawnTransform);
if (EffectActor)
{
EffectActor->SurfaceHit = HitResult;
UGameplayStatics::FinishSpawningActor(EffectActor, SpawnTransform);
}
}
// THE OnRepNotify VARIABLE HERE!
bExploded = true;
}
void AProjectile::OnRep_Exploded()
{
// DEBUG MESSAGE FOR TEST PURPOSES
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("OnRep_Exploded()!")));
FVector ProjDirection = GetActorForwardVector();
const FVector StartTrace = GetActorLocation() - ProjDirection * 200;
const FVector EndTrace = GetActorLocation() + ProjDirection * 150;
FHitResult Impact;
if (!GetWorld()->LineTraceSingleByChannel(Impact, StartTrace, EndTrace, COLLISION_WEAPON, FCollisionQueryParams(TEXT("ProjClient"), true, Instigator)))
{
Impact.ImpactPoint = GetActorLocation();
Impact.ImpactNormal = -ProjDirection;
}
Explode(Impact);
}
The problem is that the function OnRep_Exploded doesn’t seem to be fired, since the DebugMessage inside of it doesn’t get displayed!!!
Any ideas?