[ARTICLE] Explanation on how I used GameSparks Matchmaking and AWS Dedicated Server

Thanks Ryan, good info - i emailed them.

UE_SERVER is defined when compiling for the MyGameServer.exe executable. Cooking is really an orthogonal issue, but yes this binary does expect cooked server data.

So anything under UE_SERVER will disappear if I build as dedicated server…right?

Hi unit23,
Our Realtime SDK is currently in the final stages of testing for the Unreal Engine. Is this what you are looking for? Feel free to log a ticket with our support service over at / and we can answer all your questions.

Best Regards, .

Just the opposite UE_SERVER is 1 when compiling for dedicated server. See Build.h for all the details.

UGameSparksComponent is a USceneComponent. so it have to be added as an component of another scene actor . problem is that whenever i load a new level that scene actor gets deleted . so connection between ue4 app and gamespark also gets reset.
how to prevent that?
anyway to not to delete the scene UGameSparksComponent’s parent?


You need to save your GameSparksComponent in GameInstance class. For my game what I did was I created GameSparks Component in my base game mode (from this I derive all other game modes) under constructor and inside InitGame function I save the GameSparksComponent in Game Instance class. This way, I never get lost of GameSparks connection throughout the game.

Here’s a quick example:


UGameSparksComponent* GameSparksComponent;

UMyCustomGameInstance* MyCustomGameInstance;

virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override;


// In constructor
GameSparksComponent = CreateDefaultSubobject<UGameSparksComponent>(TEXT("GameSparksComponent"));

void AExampleGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
    Super::InitGame(MapName, Options, ErrorMessage);    
    MyCustomGameInstance = Cast<UMyCustomGameInstance>(GetWorld()->GetGameInstance());


UGameSparksComponent* GameSparksComponent;

void SetupGameSparksComponent(UGameSparksComponent* NewComponent);


if (GameSparksComponent == nullptr)
    GameSparksComponent = NewComponent;
    // GameSparksComponent->OnGameSparksAvailableDelegate.AddDynamic(this, &UMyCustomGameInstance::OnGameSparksConnected); // Bind your delegate

I worked around it, using only one gamemode and one player controller.

After initial login, after the player leaves the login area and begins playing i set a bool, and check on the gamemode eventbeginplay if it was already set, if yes, the gamespark disconnect/connect and loading of the login view is skipped. The menu is accessible from within the game, so once the game begins, the player can do everything anyway. I can always load a different level and hide the player from the view if required. Not sure if this yields other problems, but so far seems to work for my approach.

@ryanjon2040, do that technique works on both side of host server and client ?

where did u keep your code for game spark’s BlueprintAssignable(listener and game spark component both have these events) events ?

so far i tried to keep them in actor and gamemode.

i got same result for both place.
they work as long as i am in single player mode. or i am the one who hosting the game.

but on client side whenever client join to a session and a new world gets loaded then the GameMode and actor both get deleted. so i lose all my data stored in there and also the code.

any idea?


In my custom Game Instance class.

Game Mode doesn’t exist on clients. If you try to cast your game mode in client it will always return null. If you want data throughout the entire game (i.e: even after loading new level) you need to save your data inside Game Instance because they exist till you exit the game completely.

i have tried your code sample.
sadly in 4.11, whenever a new level was loading the UGameSparksComponent stored in UMyCustomGameInstance was getting delated. and a new one was created by new AExampleGameMode() and was stored in UMyCustomGameInstance .
and i dont want that.
may be it works differently in latest version of ue4.

no idea. how the UGameSparksComponent was getting survived on client side during joining to server.
from my knowledge ,all sceneComponent supposed to be getting collected by garbage collector.
hence no sceneComponent can survive on client side.
and sadly UGameSparksComponent is a sceneComponent .

i dediced to modify the GameSparks plugin as it’s source code available. and i hope i will be able to make it bypass garbage collection.

anyway thanks for all the answers

For the GameSparksComponent in your GameInstance class, did you mark it as UPROPERTY()?

like this for example:

UGameSparksComponent* GameSparksComponent;


here in the video i showed what is happening with that sample code.


I also have attached the source code of gamemmode , game instance and modefied version of my UGameSparksComponent.

basically , to detect if existing UGameSparksComponent is a new one or previous one , i have added this variable in it :

and then in UMyCustomGameInstance i was continuously printing the UGameSparksComponent stored in UMyCustomGameInstance 's
UGameSparksComponent* GameSparksComponent pointer.

in the video u will see that after hosting the GameSparksComponent gets cleared by garbage collector and set to null.

anyway, i have figure out a solution by modifying the gamespark plugin. most probably i will send them a pull request too.

If you dont want GameSparksComponent getting garbage collected then you should remove UPROPERTY() from it. If you look at my code example above you can see I never added UPROPERTY() for GameSparksComponent in GameInstance class.

Change from this:

UGameSparksComponent* GameSparksComponent;

to this:

UGameSparksComponent* GameSparksComponent;

See attachment also.

actually i was given the opposite concept.
i added that UPROPERTY based on this line:

"Garbage Collection

Any Object that has at least one valid pointer stored inside a UPROPERTY will not be Garbage Collected (GC)."

Also i was informed:


still i did the test after removing UPROPERTY .
now it is crashing while checking.
Bcz it is now null.
strange part is that it is not giving true for (if (GameSparksComponent == nullptr))
No idea.why

Thanks for this, it’s incredibly relevant to me, and I’ll probably have some questions for you soon.

How have you handled horizontal scaling in your AWS instance with regards to talking back to Gamesparks? Was there much work required or was it “automagic” based on your AWS setup?

u have to do it by yourself. there are some open source tools for it.
the only thing in this matter GS helps is that it can provide u how many player is playing on each server. also GS can help u by providing player geographical location.

bump + following. I have been trying to find solution its almost been 2 weeks now.

are there any video tutorials for this out there yet?
the community would thrive from some solid videos on this subject