Hey! So, I’m studying delegates on C++ and I’m a bit confused with when to use dynamic delegates. I understand that I must use it if I want to call this delegate from the blueprint side, but there is this word that is bugging me: serialization. On the docs I see that one of the main reasons to use the dynamic is if you need serialization, but what would be that? I tried googling but I haven’t found a good explanation in the Unreal context.
Can someone help me?
Hey WizardMaster, I came across this post whilst looking into some stuff about delegates myself, BenUI has a pretty good tutorial going into delegates here
It has a section about serialization, which hopefully answers your question:
Only Dynamic Delegates support serialization, but why would we care about serialization?
In our running example of binding a UI widget to the Player State’s
OnScoreChangedDelegate
, we would not normally need to serialize that binding. We could do it when the widget is created when the game starts.However, let’s instead imagine we are creating a city building game, and we have instances of an actor
AWorker
that run around and can bind to delegates that are executed when tasks are complete. In this case we could imagine that we might want to serialize those subscriptions so they are restored when re-loading a game.Then when the game saves its state, we want it to preserve those connections. For that we need to use Dynamic Delegates.
Hopefully that’s helpful, if you haven’t already found the answer yourself!
That’s a very clear explanation, thank you! After not having a response I just assumed it’s for very complex usages, and I was just using when I wanted to use the delegate with blueprints. Thank you for the response!