top of page
James Burke

Individual Project #2 - Triggers, The Long Way

Updated: May 11, 2021

In this post, I quickly dive into the engine code to help implement overlap events programmatically through finding the function signatures rather than doing so through blueprints.


As part of starting with basics, I set out to implement triggers. A trigger is an object with no visual to it. It has dimentions which a developer can adjust to make a "zone". These zones, defined by the bounds of the trigger volume, typically come with overlap events. For instance, when a player walks into a trigger volume, the effect may be a pinging sound being played.

// Trigger
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, 
Category = "Floor Switch")
class UBoxComponent* TriggerBox;

// Physical floor switch mesh; the character steps on this
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, 
Category = "Floor Switch")
class UStaticMeshComponent* FloorSwitch;

// Door that will open; the effect
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, 
Category = "Floor Switch")
UStaticMeshComponent* Door;

We have created a trigger volume, and a couple of meshes. We will be making a door and a switch/pressure pad. In the BeginPlay of the class, we add dynamic bindings to the trigger's overlap events. So far, the editor will show errors. Follow on.

TriggerBox->OnComponentBeginOverlap.AddDynamic(
this, &AFloorSwitch::OnOverlapBegin);
	
TriggerBox->OnComponentEndOverlap.AddDynamic(
this, &AFloorSwitch::OnOverlapEnd);

Back in the header we also define functions for the typical overlap events. We need the necessary parameters and usually this is done automatically for us in the editor- however we want to handle these programmatically. How do we find what parameters to use?

Right click on the event, then "Go to definition" or press F12.

Then, do the same for this (which is where you will be directed). You can also CTRL click.

This will direct you to "PrimitiveComponent.h". Now just copy the parameters starting from the first pointer parameter. Pase the arameters into your header function definition for OnOverlapBegin. Now it will look like the function from a few images above.

Now we are ready to handle overlap events programmatically! (Apply the same method to fill parameters for other overlap events such as OnOverlapEnd).

Then, make sure to set collision parameters. These equate to look like this in the editor. Query Only is for overlaps, raycasts, etc. We set the response to ignore everything initially, then overwrite it to set pawn overlap response.


Recent Posts

See All

コメント


bottom of page