Doc from here don’t explain all the process (and don’t compile):
https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Delegates/Events/index.html
doc there is different :
After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...
Reading time: 1 mins 🕑
Likes: 14 ❤
and code from unreal is different from both :
/** Called when selected level list changes. */
DECLARE_EVENT( UWorld, FOnSelectedLevelsChangedEvent);
/** Broadcasts whenever selected level list changes. */
FOnSelectedLevelsChangedEvent SelectedLevelsChangedEvent;
So what’s the right way to code events from start to end ?
Thanks.
Hey w77, where are you declaring this- is it in an interface?
Hey w77
I just tested an event declaration in an interface;
DECLARE_EVENT_OneParam( UActionManager, FEventSignature, AActor* )
in the header;
static FEventSignature MyTestEvent;
In the cpp;
FEventSignature IActionManagerInterface::MyTestEvent = {};
It compiles fine. So then all I’d need to do is bind the event to a function in the UActionManager, which is the class I’ve assigned as the owning type.
MyTestEvent.BindUObject(this, &UActionManager::SomeFunction);
Let me know if that works! If the class you’re declaring it in isnt abstract, then you probably wouldn’t want it to be static.
If it isn’t static then don’t put anything in the cpp. you shouldn’t need to initialize it…
without static :
error C2761: ‘FDisableEvent UGeneratorComponent::DisableEvent’ : member function redeclaration not allowed
public:
FDisableEvent DisableEvent;
.cpp
FDisableEvent UGeneratorComponent::DisableEvent = {};
I don’t understand why set the event public… any class anywhere can fire broadcast.
you can make it private in the header. The DECLARE_EVENT is above the class definition though. Between the #includes and the class definition…