C++ Spawn decal at OnComponentHit location?

anonymous_user_b9d6f105
Mon, 06 Apr 2015 08:23:41 +0000
Rendering

Hi, I can’t seem to figure this one out on my own, or find a solid answer. I’ve created a deferred decal with a blood splat texture. I’ve created a simple Actor c++ class, in which I assign a mesh for visual and sphere component for collision. In this class I have a void function named OnHit, which I add dynamically to OnComponentHit for the SphereComponent. This all works fine, I can debug the hit by shooting a message out on collision. I can also spawn an actor that is from one of my classes, for example

.h
TSubclassOf<SomeActor> Clone;

.cpp
Clone = SomeActor::StaticClass();

OnHit(params)
{
    MyDebugFunction("Hit");
    SomeActor* MyClone = GetWorld()->SpawnActor<SomeActor>(Clone, Loc, Rot, Params);
}

My problem is, I can’t create a C++ DecalActor, this causes the editor to crash when I attempt. When I create a C++ class from DecalComponent, all I get is the same generated code I’d get from the typical AActor type of class. I’ve also tried creating a blueprint out of my decal, as a prefab. Then I am able to grab that class with something like

.h
UBlueprint* Decal;

.cpp
static ConstructorHelpers::FObjectFinder<UBlueprint>DecalBP(TEXT("Blueprint'/Game/Blueprints/MyBP.MyBP'"));
if(DecalBP.Object != nullptr)
    Decal = DecalBP.Object;

I can build successfully, but when I try to spawn this, nothing but the “Hit” message works. Is there any way I can create a Deffered Decal in my scene, then create a C++ class from it? It doesn’t seem there would be, so how would I go about grabbing my “prefab” or Blueprint, then spawn it via C++ code in my Actor’s Hit event?

2 posts - 1 participant