I’m trying to figure out how to replicate decals so that clients can see where bullets are hitting.
So I am doing the following.
UDecalComponent* Decal = UGameplayStatics::SpawnDecalAttached(DefaultDecal.DecalMaterial, FVector(DefaultDecal.DecalSize, DefaultDecal.DecalSize, 1.0f),
SurfaceHit.Component.Get(), SurfaceHit.BoneName,
SurfaceHit.ImpactPoint, RandomDecalRotation, EAttachLocation::KeepWorldPosition,
DefaultDecal.LifeSpan);
Decal->SetIsReplicated(true);
However, the decals are still only appearing on the server and not on the client.
I am doing this within an Actor’s PostInitializeComponents
void AFPSImpactEffect::PostInitializeComponents()
{
Super::PostInitializeComponents();
UPhysicalMaterial* HitPhysMat = SurfaceHit.PhysMaterial.Get();
EPhysicalSurface HitSurfaceType = UPhysicalMaterial::DetermineSurfaceType(HitPhysMat);
// show particles
UParticleSystem* ImpactFX = GetImpactFX(HitSurfaceType);
if (ImpactFX)
{
UGameplayStatics::SpawnEmitterAtLocation(this, ImpactFX, GetActorLocation(), GetActorRotation());
}
// play sound
USoundCue* ImpactSound = GetImpactSound(HitSurfaceType);
if (ImpactSound)
{
UGameplayStatics::PlaySoundAtLocation(this, ImpactSound, GetActorLocation());
}
if (DefaultDecal.DecalMaterial)
{
FRotator RandomDecalRotation = SurfaceHit.ImpactNormal.Rotation();
RandomDecalRotation.Roll = FMath::FRandRange(-180.0f, 180.0f);
UDecalComponent* Decal = UGameplayStatics::SpawnDecalAttached(DefaultDecal.DecalMaterial, FVector(DefaultDecal.DecalSize, DefaultDecal.DecalSize, 1.0f),
SurfaceHit.Component.Get(), SurfaceHit.BoneName,
SurfaceHit.ImpactPoint, RandomDecalRotation, EAttachLocation::KeepWorldPosition,
DefaultDecal.LifeSpan);
Decal->SetIsReplicated(true);
}
}
And I am creating this AFPSImpactEffect actor on the server via the following.
if (Impact.GetActor())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("You hit ") + Impact.GetActor()->GetName());
// Deal damage to the actor we hit
DealDamage(Impact, AimDirection);
// TODO: move to function
FTransform const SpawnTransform(Impact.ImpactNormal.Rotation(), Impact.ImpactPoint);
AFPSImpactEffect* EffectActor = GetWorld()->SpawnActorDeferred<AFPSImpactEffect>(ImpactClass, SpawnTransform);
if (EffectActor)
{
EffectActor->SurfaceHit = Impact;
UGameplayStatics::FinishSpawningActor(EffectActor, SpawnTransform);
}
}
Anyone have any tips or ideas?