I am running into the same issue.
My UE4 class needs access to the object the event was sent from. However, the way it's set up I can seemingly only use static functions.
I tried to bind it using non-static like so: EventRequest.Send(&ASMission::Load_Response); but that did not work unfortunately (result: a wall of errors)
How can we bind non-static functions to LogEventRequest classes?
Any feedback on this?
Hi guys,
Check the attached file which is part of our example project. Does code like this suit you better?
Here's a snippet:
GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance(); // attach the message listeners // MatchFoundMessage gs.SetMessageListener<MatchFoundMessage>([&](GS& gsInstance, const MatchFoundMessage& message) { GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Yellow, TEXT("MatchFoundMessage")); gameSession = TSharedPtr<GameSparks::RT::IRTSession>(GameSparks::RT::GameSparksRT::SessionBuilder() .SetConnectToken(message.GetAccessToken().GetValue()) .SetHost(message.GetHost().GetValue()) .SetPort(message.GetPort().GetValue()) .SetListener(this) .Build()); gameSession->Start(); }); // MatchNotFoundMessage gs.SetMessageListener<MatchNotFoundMessage>([&](GS& gsInstance, const MatchNotFoundMessage& message) { GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Yellow, TEXT("MatchNotFoundMessage")); SendMatchmakingRequest(gs); // try again }); // MatchUpdatedMessage gs.SetMessageListener<MatchUpdatedMessage>([&](GS& gsInstance, const MatchUpdatedMessage& message) { GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Yellow, TEXT("MatchUpdatedMessage")); }); //Construct an Authentication request // send a device authentication request with a random device id. // this is done so that you can start two instances on the same machine. // In a production title, you'd use IGSPlatform::GetDeviceId() instead. GameSparks::Api::Requests::DeviceAuthenticationRequest authRequest(gs); std::srand(std::time(nullptr)); std::stringstream fake_device_id; fake_device_id << std::rand(); authRequest.SetDeviceId(fake_device_id.str()); // generate a random device id (for easy testing) authRequest.SetDeviceOS("W8"); authRequest.SetUserData(this); //Send it with a pointer to the function that will handle the response authRequest.Send(AuthenticationRequest_Response);
Cheers,
Omar
Hi
MatchFoundMessage is undefined for me. Is it something I haven't included perhaps? Please help
Chris
MatchFoundMessage its work , but this :
gameSession = TSharedPtr<GameSparks::RT::IRTSession>(GameSparks::RT::GameSparksRT::SessionBuilder() .SetConnectToken(message.GetAccessToken().GetValue()) .SetHost(message.GetHost().GetValue()) .SetPort(message.GetPort().GetValue()) .SetListener(this) .Build());
this code not working i got error here ".SetListener(this)"
i find solution you cannot use "this" as a listener ,,,, i was create the session successfully , but i have another problem ,,,,, i do not understand how i can receive packets , how the delegate run with your code????????
you just show how to create session , can you please explain how can i receive respond at OnReady delegate for example?
David Racine
Hi there,
First i must say that im learning c++ so im far to be an expert and i just started to work with GameSparks but im trying to figure why using static function for every request response instead of multicast delegate like the OnGameSparksAvailableDelegate? Having to deal with static response can be such a pain with non static members and everything else.
2 people have this question