Why do we use AddUObject instead of Add?

In the video Sam is binding a function to OnCreateSessionDelegates using the AddUObject function. I’ve been wondering why we use this method, wouldn’t just a simple Add be enough?

AddUObject, apart from binding a function, holds a reference to an object which seems to be an extra step that we don’t need. Could anyone tell me when it would be more appropriate to use Add instead of AddUObject while binding to delegates? Thanks in advance! :grin:

UObject are garbage collected. This is probably one of the most useful things to know.

1 Like

Why is it an extra step? How would it call the member function without having an object to call it on?

Add takes in a FOnCreateSessionCompleteDelegate, so you would need to create one and there’s a nice helper to create one for a member function of a UObject,

auto Delegate = FOnCreateSessionCompleteDelegate::CreateUObject(this, &UPuzzlePlatformsGameInstance::OnCreateSessionComplete);

And that’s exactly what AddUObject does. It does the first line for you.


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

Privacy & Terms