# Exception when trying to bind a UFUNCTION with AddDynamic to a Delegate

**URL:** <https://forums.unrealengine.com/t/exception-when-trying-to-bind-a-ufunction-with-adddynamic-to-a-delegate/1306192>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [September 21, 2023, 9:04am UTC](https://forums.unrealengine.com/t/exception-when-trying-to-bind-a-ufunction-with-adddynamic-to-a-delegate/1306192 "2023-09-21T09:04:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [September 21, 2023, 4:53pm UTC](https://forums.unrealengine.com/t/exception-when-trying-to-bind-a-ufunction-with-adddynamic-to-a-delegate/1306192/2 "2023-09-21T16:53:26Z")

</div>

> [@seeyouanteeius](#):
>
> P.s. Also guess i should mention this one: if I put “AddDynamic” line in ctor of my Pawn class then the exception doesn’t appear but when i play it creates another copy of my Pawn and binds that HandleReceivedBytes method to it instead of an instance of my Pawn which is on a level.

binding to a delegate should definitely not be done in the constructor of any object. It should be done on an instance of a Pawn once when required, usually during BeginPlay. The constructor is only meant to set up the class itself without accessing other objects (can be dangerous). In UE there is another reason, read this:

> [What is CDO? - #2 by anonymous\_user\_9f4576f5](https://forums.unrealengine.com/t/what-is-cdo/310820/2)

This should live on BeginPlay as well:

```auto
UdpComp->OpenReceiveSocket(TEXT("127.0.0.1"), 5228);

```

It’s hard to tell what is going on without seeing an entire call stack. If you put a breakpoint before the moment it would assert, can you find new information in previous steps listed in the callstack?

---

_[View the full topic](https://forums.unrealengine.com/t/exception-when-trying-to-bind-a-ufunction-with-adddynamic-to-a-delegate/1306192)._
