# How to code events in c++?

**URL:** <https://forums.unrealengine.com/t/how-to-code-events-in-c/303102>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [January 5, 2015, 5:38pm UTC](https://forums.unrealengine.com/t/how-to-code-events-in-c/303102 "2015-01-05T17:38:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AZOM-Games](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/azom-games/32/997248_2.png) [@AZOM-Games](https://forums.unrealengine.com/u/AZOM-Games)\
**Post date:** [January 5, 2015, 5:38pm UTC](https://forums.unrealengine.com/t/how-to-code-events-in-c/303102/1 "2015-01-05T17:38:08Z")

</div>

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](https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Delegates/Events/index.html)

doc there is different :

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> 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...

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.

---

<div class="post-metadata">

**Author:** ![robbiecooper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@robbiecooper](https://forums.unrealengine.com/u/robbiecooper)\
**Post date:** [January 5, 2015, 6:07pm UTC](https://forums.unrealengine.com/t/how-to-code-events-in-c/303102/2 "2015-01-05T18:07:37Z")

</div>

Hey w77, where are you declaring this- is it in an interface?

---

<div class="post-metadata">

**Author:** ![robbiecooper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@robbiecooper](https://forums.unrealengine.com/u/robbiecooper)\
**Post date:** [January 5, 2015, 6:20pm UTC](https://forums.unrealengine.com/t/how-to-code-events-in-c/303102/3 "2015-01-05T18:20:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AZOM-Games](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/azom-games/32/997248_2.png) [@AZOM-Games](https://forums.unrealengine.com/u/AZOM-Games)\
**Post date:** [January 5, 2015, 6:50pm UTC](https://forums.unrealengine.com/t/how-to-code-events-in-c/303102/4 "2015-01-05T18:50:24Z")

</div>

no, it’s a class event.

---

<div class="post-metadata">

**Author:** ![AZOM-Games](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/azom-games/32/997248_2.png) [@AZOM-Games](https://forums.unrealengine.com/u/AZOM-Games)\
**Post date:** [January 5, 2015, 6:50pm UTC](https://forums.unrealengine.com/t/how-to-code-events-in-c/303102/5 "2015-01-05T18:50:43Z")

</div>

without static :  
error C2761: ‘FDisableEvent UGeneratorComponent::DisableEvent’&nbsp;: 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.

---

<div class="post-metadata">

**Author:** ![robbiecooper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@robbiecooper](https://forums.unrealengine.com/u/robbiecooper)\
**Post date:** [January 5, 2015, 6:53pm UTC](https://forums.unrealengine.com/t/how-to-code-events-in-c/303102/6 "2015-01-05T18:53:06Z")

</div>

If it isn’t static then don’t put anything in the cpp. you shouldn’t need to initialize it…

---

<div class="post-metadata">

**Author:** ![robbiecooper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@robbiecooper](https://forums.unrealengine.com/u/robbiecooper)\
**Post date:** [January 5, 2015, 6:55pm UTC](https://forums.unrealengine.com/t/how-to-code-events-in-c/303102/7 "2015-01-05T18:55:16Z")

</div>

you can make it private in the header. The DECLARE\_EVENT is above the class definition though. Between the #includes and the class definition…
