# How to detect triggerbox collision with actor

**URL:** <https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 21, 2015, 10:16pm UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568 "2015-06-21T22:16:37Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_8b0af009](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8b0af009](https://forums.unrealengine.com/u/anonymous_user_8b0af009)\
**Post date:** [June 21, 2015, 10:16pm UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/1 "2015-06-21T22:16:37Z")

</div>

I need a way of checking if my player is colliding with a triggerbox in ue4

Something like this:

`if(player-\>isTouching(myTriggerBox)) { // do something }

void AMyBox::ExitTrigger(class AActor\* OtherActor, class UPrimitiveComponent\* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)  
{  
if (GEngine)  
{  
GEngine-\>AddOnScreenDebugMessage(0, 10.0f, FColor::White, TEXT(“Exit overlap”));  
}  
}  
and header definition:  
void ExitTrigger(class AActor\* OtherActor, class UPrimitiveComponent\* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);`

---

<div class="post-metadata">

**Author:** ![pagancyc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pagancyc](https://forums.unrealengine.com/u/pagancyc)\
**Post date:** [June 21, 2015, 10:45pm UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/2 "2015-06-21T22:45:54Z")

</div>

In your trigger box constructor specify the function you want called like this:

```
MyBox->OnComponentBeginOverlap.AddDynamic(this, &AMyTriggerActor::TriggerEnter);  
// I call it TriggerEnter, call it whatever you like

```

and then have a function that does what you want to have happen:

```
void AMyTriggerActor::TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
//do stuff
return;
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8b0af009](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8b0af009](https://forums.unrealengine.com/u/anonymous_user_8b0af009)\
**Post date:** [June 22, 2015, 12:31am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/3 "2015-06-22T00:31:18Z")

</div>

Thanks so much man, I really appreciate it!

---

<div class="post-metadata">

**Author:** ![pagancyc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pagancyc](https://forums.unrealengine.com/u/pagancyc)\
**Post date:** [June 22, 2015, 12:34am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/4 "2015-06-22T00:34:03Z")

</div>

I’ve gotten help here, only fair that I pass it along.

If you upvote the answer and mark your question resolved, it will be helpful for the next person searching this topic.

And I will also get some sweet sweet internet karma! 😉

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8b0af009](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8b0af009](https://forums.unrealengine.com/u/anonymous_user_8b0af009)\
**Post date:** [June 22, 2015, 12:52am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/5 "2015-06-22T00:52:03Z")

</div>

@pagancyc  
I’ve tried using your advice, but when I try to call the adddynamic function I cannot find it, only Add, AddUnique and \_\_Internal\_AddDynamic. The class is of type actor, what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![pagancyc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pagancyc](https://forums.unrealengine.com/u/pagancyc)\
**Post date:** [June 22, 2015, 1:08am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/6 "2015-06-22T01:08:13Z")

</div>

That’s odd, AddDynamic doesn’t show up in my dropdown either, but it compiles and works. No idea what it doesn’t show up, kind of bizarre.

Here is a larger code dump, maybe it will help…

MyStuffDoer.h:

```
class STUFFDEMO_API AMyStuffDoer : public AActor
{
	GENERATED_BODY()
	
	AMyStuffDoer(const FObjectInitializer& ObjectInitializer);

	UShapeComponent* Box;

	UFUNCTION()
		void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
}

```

MyStuffDoer.cpp:

```
AMyStuffDoer::AMyStuffDoer(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
	Box = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Box"));
	Box->bGenerateOverlapEvents = true;
	Box->SetRelativeScale3D(Stretch);
	RootComponent = Box;
	Box->OnComponentBeginOverlap.AddDynamic(this, &AMyStuffDoer::TriggerEnter);
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8b0af009](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8b0af009](https://forums.unrealengine.com/u/anonymous_user_8b0af009)\
**Post date:** [June 22, 2015, 1:39am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/7 "2015-06-22T01:39:14Z")

</div>

@pagancyc  
Thanks! Just one more thing, I tried adding a OnComponentEndOverlap dynamic like so:  
Box-\>OnComponentEndOverlap.AddDynamic(this, &AMyBox::TriggerExit);  
Doing so gave me the error no instance of function template matches the argument list. Any ideas?

---

<div class="post-metadata">

**Author:** ![pagancyc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pagancyc](https://forums.unrealengine.com/u/pagancyc)\
**Post date:** [June 22, 2015, 1:41am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/8 "2015-06-22T01:41:04Z")

</div>

Did you declare it in your header file?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8b0af009](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8b0af009](https://forums.unrealengine.com/u/anonymous_user_8b0af009)\
**Post date:** [June 22, 2015, 1:47am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/9 "2015-06-22T01:47:00Z")

</div>

@pagancyc Yes, I sure did

---

<div class="post-metadata">

**Author:** ![pagancyc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pagancyc](https://forums.unrealengine.com/u/pagancyc)\
**Post date:** [June 22, 2015, 1:50am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/10 "2015-06-22T01:50:33Z")

</div>

Well, then you’ve got me stumped. I’ve never seen any difference in declaration/syntax between the two other than ‘Begin’ and ‘End’.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8b0af009](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8b0af009](https://forums.unrealengine.com/u/anonymous_user_8b0af009)\
**Post date:** [June 22, 2015, 1:52am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/11 "2015-06-22T01:52:41Z")

</div>

Heres my function definition:  
void AMyBox::ExitTrigger(class AActor\* OtherActor, class UPrimitiveComponent\* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)  
{  
if (GEngine)  
{  
GEngine-\>AddOnScreenDebugMessage(0, 10.0f, FColor::White, TEXT(“Exit overlap”));  
}  
}  
and header definition:  
void ExitTrigger(class AActor\* OtherActor, class UPrimitiveComponent\* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

I could swear nothing is wrong, anyways let me know if you see whats wrong

---

<div class="post-metadata">

**Author:** ![pagancyc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pagancyc](https://forums.unrealengine.com/u/pagancyc)\
**Post date:** [June 22, 2015, 2:24am UTC](https://forums.unrealengine.com/t/how-to-detect-triggerbox-collision-with-actor/322568/12 "2015-06-22T02:24:21Z")

</div>

I misspoke earlier, there is a difference besides Begin/End. The End function has different arguments:

```
void AMyStuffDoer::TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
...
}
```
