So I’m trying to create an event accessible in Blueprint from a custom component. As I understand it from reading many of the answers here, that’s only doable using a multicast delegate.
So I set out to do this. My .h file is as follows:
#pragma once
#include "Components/ActorComponent.h"
#include "CharacterTrigger.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnTriggerEnterSignature);
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYGAME_API UCharacterTrigger : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UCharacterTrigger();
// Called when the game starts
virtual void BeginPlay() override;
// Called every frame
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
UPROPERTY(BlueprintAssignable, Category="Custom")
FOnTriggerEnterSignature OnTriggerEnter;
UFUNCTION()
void TriggerEnterCheck(AActor* Other);
UFUNCTION()
void TriggerExitCheck(AActor* Other);
};
However OnTriggerEnter does not show up under Collision when right click on a blueprint for an Actor with a CharacterTrigger on it. Am I missing something?
What exactly are you trying to do? If you are simply trying to use blueprints to call a function written in code then you only have to use the BlueprintCallable specifier in the UFUNCTION() macro. Any function defined as BlueprintCallable also has to have a Category. This will allow the editor to recognize the function so that it shows up in the blueprint event graph. It is similar behavior for a variable as well. In the UPROPERTY() macro you use the BlueprintReadWrite specifier to see and edit the variable inside the blueprint.
I want to have an event node that I can call from code attached to a component I define in code. I want that event to be defined by the component because it will be a common event used throughout the game.
This has been described elsewhere eg in this Answer:
Following the post you referenced will provide the event in the details panel when the component is selected inside a blueprint. In your case when you select your CharacterTrigger component inside a blueprint you should see the OnTriggerEnter function at the bottom of the Details panel. If you want the function to appear when you right click and type in the name then you’ll want to make the function BlueprintCallable inside the UFUNCTION() macro.
Ah thanks. But that would be for calling native code from Blueprints (a blue node). What I want is a red node, for triggering a blueprint event from native code. I’d like to add a basic event like one of the built in ones such as On Destroyed or On Clicked. As I understand it the normal way of doing this is using BlueprintImplementableEvent, but that is only usable for Actors not Components. For components I need to use DECLARE_DYNAMIC_MULTICAST_DELEGATE as described here:
Instead of using OnBeginOverlap in level blueprints, I’d like to create my own version of it that only fires when a specific set of criteria are met (criteria that I’ll check for in code before determining whether or not to fire the event).
So essentially, I’d like to be able to create a red node like the following in a level blueprint:
And have that red node be available in the right click menu like this:
I think I may know what you are getting at. If you want to get a custom code event that will give you a Blueprint node to use, you would want to use something similar to the following: