Why is my C++ Event not visible in Blueprint?

Hi everyone,i’m trying to make the “OnMouseClick” event visible to my blueprint.
The problem is that,it is only visible,when i create a new blueprint in the editor based on the interface containing the event.
But if i instead,extends that interface in a C++ class and then use an object of that class in a blueprint,the event does not appear in the editor’s list.

My interface:
#pragma once

#include "HUDCEventsInterface.generated.h"

UINTERFACE(MinimalAPI)
class UHUDCEventsInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

class IHUDCEventsInterface
{
	GENERATED_IINTERFACE_BODY()

public:
	UFUNCTION(BlueprintImplementableEvent, meta = (FriendlyName = "On Mouse Click"))
		void OnMouseClick(const TScriptInterface < IHUDCEventsInterface > &clicked);
};

How i extend the class:

UCLASS(Blueprintable)
class UHUDCButton : public UHUDCComponent ,public IHUDCEventsInterface

Now,in the HUD blueprint,i created an object “UHUDCButton”,but the event does not appear in the list.

What am i doing wrong?
Thanks in advance.

Did you tried searching in “Library” list? because the context list might miss it. Also why you implement events in interface instead of base class UHUBComponent, instead like other engine code does?

A guess here, but did you try declaring the function as virtual?

Oh sorry i forgot ^^’ Event functions works only locally because explointing function override, if you no inside the class you can’ override function so you can’t use that. In order to make events that works anywhere you need to create delegate. Delegate decleration needs to be outside of class

//standard delegate only one function can be binded to it, use BindDynamic(...) to bind function
//one bind will replace old one
DECLARE_DYNAMIC_DELEGATE( FSomeDelegate );
//Multi cast delegate can bind multiple functions, use AddDynamic(...) to add function to multicast bind
DECLARE_DYNAMIC_MULTICAST_DELEGATE( FSomeDelegate );
//Delegate can have arguments, by adding "_OneParam"
//for more arguments you use "_TwoParam", "_ThreeParam" and so on
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParam( FSomeDelegate, ArgType1, ArgName1, ArgType2, ArgName2 );
//Arguments work the same in non-multicast delegate

Now you need to create property with “BlueprintAssignable” to which you will be able to bind functions, use class name which you used in delegate

UPROPERTY(BlueprintAssignable, Category="Somehing")
FSomeDelegate OnSomething;

This alone should let you do external event binds in blueprint :slight_smile: now in C++ binding is a little bitty more complex:

OnSomething.AddDynamic(SomeObject, &SomeClass::SomeFunction);

First argument is object in which function is located (use “this” if you want to bind inside the class), 2nd argument is pointer to function that will be called on event. Use BindDymanic() if you use non-multicast delegate, also keep in mind ha binded function arguments need to fit delegate arguments

Now to raise the event you need to call:

OnSomething.Broadcast();

On which all currently binded functions will be called, if you use delegate with arguments you need to input arguments in to Broadcast():

OnSomething.Broadcast(true, 0);

Thats all! ^^ And i still hink you need to add those events inside of base class insted of interface, thats how most classes work in engine

IF you wan some example of delegate use, try looking on engine source code, AActor class got lot of them so search for Actor.h and Actor.cpp

Sorry i forgot about delegates ^^’ check my anwser

Thanks a lot for the complete and detailed answer,as you said,i implemented everything in the base class and everything worked.
I was approaching the problem totally in the wrong way.

Thanks again.

This (turning off “Context Sensitive” in search) is the right answer to the problem I’ve fought for the last hour :smiley: Thanks

Hey I’m looking to do something very similar to this and I can’t get it to work! Can you please post your working code?

I know people use DECLERE_EVENT now days, i didn’t use it yet so not sure how it works. But method i mentioned here i still used in engine so it should work

Did you manage to get this working ?