forked from Harrison1/unrealcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyInterfaceTriggerVolume.cpp
More file actions
59 lines (53 loc) · 1.92 KB
/
MyInterfaceTriggerVolume.cpp
File metadata and controls
59 lines (53 loc) · 1.92 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Harrison McGuire
// UE4 Version 4.20.2
// https://github.com/Harrison1/unrealcpp
// https://severallevels.io
// https://harrisonmcguire.com
#include "MyInterfaceTriggerVolume.h"
#include "Kismet/GameplayStatics.h"
#include "MyInterface.h"
AMyInterfaceTriggerVolume::AMyInterfaceTriggerVolume()
{
OnActorBeginOverlap.AddDynamic(this, &AMyInterfaceTriggerVolume::OnOverlapBegin);
OnActorEndOverlap.AddDynamic(this, &AMyInterfaceTriggerVolume::OnOverlapEnd);
}
void AMyInterfaceTriggerVolume::OnOverlapBegin(class AActor* OverlappedActor, class AActor* OtherActor)
{
// check if Actors do not equal nullptr and that
if (OtherActor && OtherActor != this && !Cast<AMyInterfaceActor>(OtherActor))
{
TArray<AActor*> MyInterfaceActors;
UGameplayStatics::GetAllActorsWithInterface(GetWorld(), UMyInterface::StaticClass(), MyInterfaceActors);
if(MyInterfaceActors.Num() > 0)
{
for (auto& Act : MyInterfaceActors)
{
IMyInterface* InterfaceActor = Cast<IMyInterface>(Act);
if(InterfaceActor)
{
InterfaceActor->SaySomething();
InterfaceActor->ReactToTriggerBegin();
}
}
}
}
}
void AMyInterfaceTriggerVolume::OnOverlapEnd(class AActor* OverlappedActor, class AActor* OtherActor)
{
if (OtherActor && OtherActor != this && !Cast<AMyInterfaceActor>(OtherActor))
{
TArray<AActor*> MyInterfaceActors;
UGameplayStatics::GetAllActorsWithInterface(GetWorld(), UMyInterface::StaticClass(), MyInterfaceActors);
if(MyInterfaceActors.Num() > 0)
{
for (auto& Act : MyInterfaceActors)
{
IMyInterface* InterfaceActor = Cast<IMyInterface>(Act);
if(InterfaceActor)
{
InterfaceActor->ReactToTriggerEnd();
}
}
}
}
}