This line of code is spewing all sorts of errors. The last few lines are as follows:
/work/unreal/UnrealEngine/Engine/Source/Runtime/Core/Public/Delegates/DelegateSignatureImpl.inl(324,67) : error: no member named ‘AsShared’ in ‘FMyServerBrowserUtils’
return CreateSP( StaticCastSharedRef< UserClass >( InUserObject->AsShared() ), InFunc );
/work/unreal/UnrealEngine/Engine/Source/Runtime/Core/Public/Delegates/DelegateSignatureImpl.inl(790,10) : note: in instantiation of function template specialization ‘TBaseDelegate_OneParam<void, bool>::CreateSP<FMyServerBrowserUtils>’ requested here
*this = CreateSP( InUserObject, InFunc );
/home/redneck/Documents/Unreal Projects/MyGame/Source/MyGame/Private/MyServerBrowser.cpp(57,33) : note: in instantiation of function template specialization ‘TBaseDelegate_OneParam<void, bool>::BindSP<FMyServerBrowserUtils>’ requested here
OnFindSessionCompleteDelegate.BindSP(this, &FMyServerBrowserUtils::OnFindSessionsComplete);
BindSP is really a shortcut for CreateSP, where the SP stands for shared pointer. In order to obtain a shared pointer, you normally have to call MakeShareable, i.e.:
TSharedPtr<FMyServerBrowserUtils> BrowserUtils = MakeShareable( new FMyServerBrowserUtils() );
That’s the nitty gritty details. You could manually create a delegate in this fashion and assign it to OnFindSessionCompleteDelegate. But that’d be troublesome, especially since you’re already in the class and you don’t really care how it is being referenced by the delegate.
Thankfully, UE4 provides a handy little construct to avoid having to manually create shared pointer delegates. This is the “AsShared” function that’s being called by the BindSP shortcut. In order for your class to have this, it first needs to inherit from TSharedFromThis, like so:
class FMyServerBrowserUtils : public TSharedFromThis<FMyServerBrowserUtils>
The template syntax might seem a bit weird, but it allows automagically adding to your class a “AsShared” function that returns a TSharedPtr<FMyServerBrowserUtils>. Then BindSP will happily use that shared pointer to create a delegate.
Hmmm. This is a problem. The troublesome call is occuring inside one of the class methods. There’s no pointer inside the method (other than ‘this’) because the class hasn’t been instantiated yet. I’m guessing that the delegates will need to be assigned after the class is instantiated. Correct?
You can ignore my explanation of shared pointers if it wasn’t clear, I was just trying to provide some context to the nature of TSharedPtrs. But that’d require more than a few lines.
All you should need to do is add the inherited “public TSharedFromThis<FMyServerBrowserUtils>” to your class and that’ll take care of it.
Hooray! The BindUObject fixed part of the problem. But there one more still in there. I’m assuming it’s the same problem. But google won’t tell me what it needs to be changed to:
There are a few different ways to bind to delegates, BindRaw, BindStatic, BindSP, BindUObject (and, in 4.6, BindLambda). They’re all described in Delegate.h if you wish to learn more about them.