I am trying to have this ball hit the floor with a decal attach to it. What is the proper way to use the Spawn Decal Attached function. I had created a material and set it to deferred decal. I set a decal actor in C++ then created the Decal actor in BP. I don’t know the proper way to use this function, could anyone help? I know in BP there is a spawn decal at location function. How do I properly cast to the decal, do I have to attach the decal to a bone etc?
This would probably be one of those instances you’d want to use blueprints. Personally i’d make a BlueprintNativeEvent and then use the Spawn Decal At Location node, which makes finding impact nodes easier too but you can make it take in an FVector and just use that. Its a messier solution - sure - but if you just want something to be up and running its really not worth sitting there bashing your head on your keyboard for something thats already prebuilt in the engine
Edit: for this solution you need a reference to a UMaterialInstance and pass that through the function because the spawn decal requires it. Then you’ll need to determain the forward vector - since its a ball spawning this stuff im guessing its on the ground, thatll be getting the up vector and converting it into a rotator which is really simple in bp but im sure its pretty easy in cpp too.
Put a debug line wherever you’re calling the hit ground function. If you’re using on overlap functions or on hit functions you might be running into the same dumb problem im running into. My advice right now though is put a debug line everywhere in the line that has to do with the decal spawning
Also make sure its a material INSTANCE it has to be a material instance or it wont work because the decal systems use material instances only
I have tried using Blueprints for this and for some reason when the actor hits the ground the material doesn’t spawn I have the material set to deferred decal and the blend mode set to translucent on the material that is why I tried doing in CPP. The blueprints are inside of the actor hitting the floor.
327438-
Dog you’re not listening to what im saying. Where ever you have your hit event in the ball - where ever the ball determines that it has hit the ground - must not be working if it isnt spawning. That means theres an issue with the collision that you need to work on.
my guess is you’re having the exact same issue as me. Peep the video on my latest question to see what im talking about. Overlap events dont seem to work if one actor is stationary, in this instance the actor is the floor for you. So that means that overlap events wont work for us regardless of how its handled
Put a debug line during the conditional where its supposed to spawn. If it doesnt fire that means there isnt collision which means you need to redo the collision system
I was about to come on here with a hacky solution because I discovered that the box collision component magically works but then I saw you put generate collision on the floor. - I did that for my character mesh and my problem was solved too. You’re the MVP!
Here is in order to save memory and for posterity.
Here is the C++ code conversion.
>
//.h
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “BloodDecal”)
UMaterialInstance* BloodDecal;
//.cpp
/Call this in the beginplay./
SphereComponent->OnComponentHit.AddDynamic(this, &ASphere::OnSphereCollHit);
void ASphere::OnSphereCollHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
FVector DecalSize(20.0f, 20.0f, 20.0f);
FRotator RandomDecalRotation = Hit.Location.Rotation();
FVector DecalLocation = Hit.Location;
UGameplayStatics::SpawnDecalAtLocation(//Here is the actor that comes in contact.->OtherActor,BloodDecal,DecalSize,DecalLocation, RandomDecalRotation);
}