I am trying to spawn Decal Actor in level by using SpawnActor<>() function (somehow UGameplayStatics::SpawnDecalAtLocation didn’t work).
and this is my code:
void ASplashTestBall::NotifyHit(class UPrimitiveComponent* MyComp, class AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit)
{
Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit);
if (!bCanJump)
{
// Set up Transform
FVector Size = { FMath::RandRange(1.f, 2.f), FMath::RandRange(1.f, 2.f), FMath::RandRange(1.f, 2.f) };
FVector Location = Hit.ImpactPoint + Hit.ImpactNormal * 40.f;
FRotator Rotation = (-Hit.Normal).Rotation();
FTransform Transform(Rotation, Location, Size);
// Set up Material
UMaterialInstanceDynamic* SplashDecalMID = UMaterialInstanceDynamic::Create(SplashDecalMaterial, nullptr);
SplashDecalMID->SetScalarParameterValue(TEXT("Frame"), FMath::Rand() % 6);
// Spawn Decal Actor
//UGameplayStatics::SpawnDecalAtLocation(this, SplashDecalMID, Size, Location, Rotation); // Why not working ???
ADecalActor* NewDecal = GetWorld()->SpawnActor<ADecalActor>(ADecalActor::StaticClass(), Transform);
NewDecal->SetDecalMaterial(SplashDecalMID);
NewDecal->GetDecal()->SetFadeOut(20.f, 5.f);
NewDecal->SetActorRotation(Rotation); // I dont know why I need Do it again
DrawDebugSphere(GetWorld(), Hit.ImpactPoint + Hit.ImpactNormal * 40.f, 19.f, 20.f, FColor::Red, true);
}
bCanJump = true;
}
with these code, things go well
if I don’t have
NewDecal->SetActorRotation(Rotation)
after spawn, the rotation of Decal Actor looks like be changed by something
Why I need adjust rotation after spawning?
Why SpawnDecalAtLocation didn’t work?
I’ll be so appreciated.