Delegate function deprecated

I’m not sure the exact version it was removed, but as of 4.19.2 AddOnCreateSessionCompleteDelegate no longer exists in IOnlineSession. The replacement is AddOnCreateSessionCompleteDelegate_Handle, which does not support the AddUObject macro and results in the following compiler error:
error C2228: left of ‘.AddUObject’ must have class/struct/union

The solution is simple enough and can actually be found in the ShooterGame example project.

First, you need to declare a delegate handle in the game instance header:
FOnCreateSessionCompleteDelegate OnCreateSessionCompleteDelegate;

Next, in the game instance constructor you obtain the handle via the CreateUObject function:
OnCreateSessionCompleteDelegate = FOnCreateSessionCompleteDelegate::CreateUObject(this, &UPuzzlePlatformerGameInstance::OnCreateSessionComplete);

Now you can simply pass this handle to AddOnCreateSessionCompleteDelegate_Handle after creating the session:
pSession->AddOnCreateSessionCompleteDelegate_Handle(OnCreateSessionCompleteDelegate);

Hope that helps anyone who encounters the same error.
Cheers!

And of course, going back through the video again I realized that Sam was using OnCreateSessionCompleteDelegates which does indeed support the AddUObject macro.

Oh well, perhaps my note will be useful to anyone using the Add* version of the functions as I was trying to do. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms