Trigger & Relay Plugin 1.0.0
Easy signal setups done right
Loading...
Searching...
No Matches
Advanced Features

Trigger Ids

By default, it is assumed that most actors have one trigger component. It is possible to manage multiple components per actor though. To differentiate each component a trigger has an FName Id property.

Listener components will query all triggers of a target actor unless an Id is specified. In this case they will query the target actor for a trigger component matching the given id and only register to that one.

Custom Relays

AFtsCustomRelay handles the boilerplate setup for a relay. It contains one trigger and one listener. When the listener fires the On Signal Received Event is called, which is where custom behavior can be implemented. See the Keypads example.

The custom relay uses a basic trigger component, but it can be changed in a subclass.

In Blueprints by selecting the trigger component and changing its class in the component class dropdown.

In C++ by overriding the constructor and using the ObjectInitializer to assign a new class to the Trigger component.

.h

AExampleRelay(const FObjectInitializer& ObjectInitializer);

.cpp

AExampleRelay::AExampleRelay(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass("Trigger", UFtsIntegerTriggerComponent::StaticClass()))
{
}

Custom Signal Payload

The signal being broadcast by a trigger does not need to be linked. Toggle trigger send boolean signals and Integer triggers send integer values, but that is not enforced. What they really send is Instanced Structs. These can carry any USTRUCT or Blueprint Struct. The Keys make use of this by sending an entirely different struct with a string value.

The custom struct should include a property named "Instigator" of the type Actor and a property named "Source" of the type Fts Trigger Signal Component. If these are not present the Get Source / Get Instigator methods will fail.

For Blueprints, since struct inheritance is not supported, simply create a new struct and configure it in any way needed.

Sending

Then call the Broadcast Signal function on a trigger component and pass in an instanced struct made from the custom struct.

In C++ it's recommended to inherit from FFtsTriggerSignal. It already contains the Instigator and Source properties.

.h

USTRUCT(BlueprintType)
struct FExampleSignal : public FFtsTriggerSignal
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Signal")
FVector CustomData;
};

.cpp

FExampleSignal Signal;
Signal.Source = Trigger;
Signal.Instigator = Instigator;
Signal.CustomData = FVector::UpVector;
FInstancedStruct SignalInstance = FInstancedStruct::Make(Signal);
Trigger->BroadcastTriggerSignal(SignalInstance);

Receiving

On the other side the contained struct can be obtained from the instanced struct.

In Blueprints, by using the Get Instanced Struct Value function which initially returns a wildcard. Creating and connecting a break node for a struct will determine the pin type and whether the cast is Valid or not.

In C++ there are several ways to query the contained struct, the most safe is to query a pointer that can be null if the wrapped struct is of the wrong type.

.cpp

FInstancedStruct SignalInstance = { ... };
if(const FExampleSignal* SignalPtr = SignalInstance.GetPtr<FExampleSignal>())
{
FVector Data = SignalPtr->CustomData;
}