What are the purpose of delegate handles?

Thanks for the reply!

So I think I basically get the gist of what they’re doing in your example, but I’m confused about something. It’s looks like in your example, you’re using the delegate handle as the delegate itself. Such as in this bit of code:

PostInitWorldDelegateHandle = FCoreUObjectDelegates::PostLoadMapWithWorld.AddUObject(this, &UST_WorldSubsystem::PostInitWorldInternal);

Whereas in the other example I was looking at, a delegate was set:

OnCreateSessionCompleteDelegate = FOnCreateSessionCompleteDelegate::CreateUObject(this, &UNWGameInstance::OnCreateSessionComplete)

And then a separate handle created which references the delegate (“Sessions” here being a reference to the IOnlineSessions interface)

OnCreateSessionCompleteDelegateHandle = Sessions->AddOnCreateSessionCompleteDelegate_Handle(OnCreateSessionCompleteDelegate);

A nearly identical example can be found in the UE4 Shooter Game example from Epic themselves (although this is from 2017, so perhaps something has changed?)

I suppose what I’m not understanding is what exactly the use of handles in the latter two examples is even doing :thinking: It seems like they’re just being set and then cleared when the function completes without ever being used to do anything, meaning we could remove them and it wouldn’t have any affect on the functionality at all. Are they just there as a reference in case we want to use them for something else later?

EDIT: So I tried actually commenting out all the handles (but leaving the delegates themselves alone) in my project. It compiled and launched fine, but when I tried to create a server nothing happened. It works fine when they’re not commented out. Guess that means they’re doing something under the hood. I’ll have to reference the backup of the version I had set up previously that didn’t use handles at all to figure out what I changed.