Hello ,
Apparently I screwed up my report. I apologize for not digging deeper on it.
However, I did now.
I compiled ShooterDemo for both 4.10 and 4.11 and compared the results.
The function I analyzed in question is AShooterImpactEffect::PostInitializeComponents()
, line 34:
FRotator RandomDecalRotation = SurfaceHit.ImpactNormal.Rotation();
I tested pressing play and aiming down, and firing a single bullet. In both versions, the result returned was the same.
However, I dug further in UGameplayStatics::SpawnDecalAttached() and found why the spawned decal is odd.
Previously (4.10), the code for this function was (File: GameplayStatics.cpp) :
UDecalComponent* CreateDecalComponent(class UMaterialInterface* DecalMaterial, FVector DecalSize, UWorld* World, AActor* Actor, float LifeSpan)
{
const FMatrix DecalInternalTransform = FRotationMatrix(FRotator(0.f, 90.0f, -90.0f));
UDecalComponent* DecalComp = NewObject<UDecalComponent>((Actor ? Actor : (UObject*)World));
DecalComp->bAllowAnyoneToDestroyMe = true;
DecalComp->DecalMaterial = DecalMaterial;
DecalComp->DecalSize = DecalInternalTransform.TransformVector(DecalSize);;
DecalComp->bAbsoluteScale = true;
DecalComp->RegisterComponentWithWorld(World);
if (LifeSpan > 0.f)
{
DecalComp->SetLifeSpan(LifeSpan);
}
return DecalComp;
}
Now (4.11) it is:
UDecalComponent* CreateDecalComponent(class UMaterialInterface* DecalMaterial, FVector DecalSize, UWorld* World, AActor* Actor, float LifeSpan)
{
UDecalComponent* DecalComp = NewObject<UDecalComponent>((Actor ? Actor : (UObject*)World));
DecalComp->bAllowAnyoneToDestroyMe = true;
DecalComp->DecalMaterial = DecalMaterial;
DecalComp->DecalSize = DecalSize;
DecalComp->bAbsoluteScale = true;
DecalComp->RegisterComponentWithWorld(World);
if (LifeSpan > 0.f)
{
DecalComp->SetLifeSpan(LifeSpan);
}
return DecalComp;
}
To test, since I can’t modify the source code on the 4.11 engine version (I can’t compile it), I did the transform in the void AShooterImpactEffect::PostInitializeComponents()
function.
I changed from:
if (DefaultDecal.DecalMaterial)
{
FRotator RandomDecalRotation = SurfaceHit.ImpactNormal.Rotation();
RandomDecalRotation.Roll = FMath::FRandRange(-180.0f, 180.0f);
UGameplayStatics::SpawnDecalAttached(DefaultDecal.DecalMaterial, FVector(DefaultDecal.DecalSize, DefaultDecal.DecalSize, 1.0f),
SurfaceHit.Component.Get(), SurfaceHit.BoneName,
SurfaceHit.ImpactPoint, RandomDecalRotation, EAttachLocation::KeepWorldPosition,
DefaultDecal.LifeSpan);
}
To
if (DefaultDecal.DecalMaterial)
{
FRotator RandomDecalRotation = SurfaceHit.ImpactNormal.Rotation();
RandomDecalRotation.Roll = FMath::FRandRange(-180.0f, 180.0f);
const FMatrix DecalInternalTransform = FRotationMatrix(FRotator(0.f, 90.0f, -90.0f));
const FVector DecalSizeLocal = FVector(DefaultDecal.DecalSize, DefaultDecal.DecalSize, 1.0f);
FVector DecalSizeCorrected = DecalInternalTransform.TransformVector(DecalSizeLocal);
UGameplayStatics::SpawnDecalAttached(DefaultDecal.DecalMaterial, DecalSizeCorrected,
SurfaceHit.Component.Get(), SurfaceHit.BoneName,
SurfaceHit.ImpactPoint, RandomDecalRotation, EAttachLocation::KeepWorldPosition,
DefaultDecal.LifeSpan);
}
and it works again.
I don’t understand why the CreateDecalComponent()
function was changed… Apparently it used to make the decals always face the player - but I do understand it might make the function more flexible, if there are other uses.
Do you happen to have any idea why it changed and if it will stay that way (so I merge those changes with my code) ?
Should I open another report concerning this, or can you edit and fix this topic for me?
Thank you in advance, and I apologize again for this rushed report.
Cheers!