I’m trying to create a decal in c++, but I’m getting stuck on the first parameter because I can’t choose what decal material I want to use like in blueprint. I’m using the function UGameplayStatics::SpawnDecalAttached by the way.
So far, my code is
void ACPP_Character::ShootLine() {
auto camManager = UGameplayStatics::GetPlayerCameraManager(this, 0);
FVector startCameraLocation = camManager->GetCameraLocation();
FVector endCameraLocation = startCameraLocation + (camManager->GetActorForwardVector() * 50000);
FHitResult outHit;
TArray<TEnumAsByte> traceObjectTypes;
traceObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECollisionChannel::ECC_WorldStatic));
TArray<AActor*> ignore;
ignore.Add(GetOwner());
bool result = UKismetSystemLibrary::LineTraceSingleForObjects(this, startCameraLocation, endCameraLocation,
traceObjectTypes, false, ignore, EDrawDebugTrace::Persistent, OUT outHit, true);
if (result) {
SpawnBulletHole(outHit);
}
}
void ACPP_Character::SpawnBulletHole(const FHitResult & HitResult) {
static ConstructorHelpers::FObjectFinder MaterialFinder(TEXT(“/Game/Materials/BulletHoleMaterial.BulletHoleMaterial”));
if (MaterialFinder.Succeeded()) {
UGameplayStatics::SpawnDecalAttached(
MaterialFinder.Object,
FVector(20, 20, 24),
HitResult.GetComponent(),
NAME_None,
HitResult.Location,
UKismetMathLibrary::MakeRotFromX(HitResult.Normal),
EAttachLocation::KeepWorldPosition,
10.0f
);
}
}
but the MaterialFinder does not work and is causing a breakpoint.