While our game may be running without any issues in the editor or even in…
Generating Overlap Events
In Unreal Engine 4 provides an easy way to generated overlap events. Overlap events consist of BeginOverlap and EndOverlap. In this tutorial I’m going to create a custom trigger that uses both functions.
Creating a Custom Trigger Box
In order to create a custom trigger box add a new C++ class which inherits from the TriggerBox class. Then, add the following functions into the header file:
Mark the functions with the UFUNCTION macro otherwise these functions won’t fire.
Implementing the logic of the Custom Trigger
In order for the events to fire, first we need to register that we want to be informed when an actual overlap occurs. The best place to register these events is right after the BeginPlay function. To do so, type the following implementation of the BeginPlay in your source file (the implementations of both OnTriggerEnter and on TriggerExit are included) :
That’s it, to test your trigger, create a Blueprint based on the above class and place it in your level (don’t forget to resize the box from the Editor). Then, control your character and test both overlaps. Your output should be similar to the image below:
Finally! A C++ tutorial with code that’s not outdated!