forked from Harrison1/unrealcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnComponentHit.cpp
More file actions
30 lines (26 loc) · 1.01 KB
/
OnComponentHit.cpp
File metadata and controls
30 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Harrison McGuire
// UE4 Version 4.20.2
// https://github.com/Harrison1/unrealcpp
// https://severallevels.io
// https://harrisonmcguire.com
#include "OnComponentHit.h"
#include "Components/BoxComponent.h"
// Sets default values
AOnComponentHit::AOnComponentHit()
{
// Use a sphere as a simple collision representation
MyComp = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComp"));
MyComp->SetSimulatePhysics(true);
MyComp->SetNotifyRigidBodyCollision(true);
MyComp->BodyInstance.SetCollisionProfileName("BlockAllDynamic");
MyComp->OnComponentHit.AddDynamic(this, &AOnComponentHit::OnCompHit);
// Set as root component
RootComponent = MyComp;
}
void AOnComponentHit::OnCompHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
{
if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("I Hit: %s"), *OtherActor->GetName()));
}
}