Hello all,
I’m a new developer with Unreal Engine and I’m trying to get an actor of mine to be able to collide with itself. I feel like this should be fairly simple, but the only way I have been able to achieve this is when the actor is simulating physics, which is not what I’m looking for. Here is the code I have in the constructor of my actor:
ARocket::ARocket()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
//set mesh
VisualMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
VisualMesh->BodyInstance.SetCollisionProfileName("Projectile");
VisualMesh->OnComponentHit.AddDynamic(this, &ARocket::OnHit);
//VisualMesh->SetSimulatePhysics(true);
VisualMesh->SetNotifyRigidBodyCollision(true);
VisualMesh->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> VisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_WideCapsule.Shape_WideCapsule"));
if (VisualAsset.Succeeded())
{
VisualMesh->SetStaticMesh(VisualAsset.Object);
VisualMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
VisualMesh->SetRelativeScale3D(FVector(0.5f, 0.5f, 1.0f));
}
}
You can see under the “set mesh” comment I have my collision code, but for some reason, when this object collides, nothing happens?!? All I have in my OhHit function is the following:
void ARocket::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
Destroy();
}
When two of my actors collide, none of them are destroyed, they just keep on moving. How can I fox this? Any help is appreciated.