Sign In Register

How can we help you today?

Start a new topic

Check if online

I would like to send a message to an array of players only if they are online. 

If they are not, they will get a complete game state update when login in, and do not need to receive that message later.

How can i read that crucial "online" field in the player collection?

Also, I'm not using challenges.

Thanks for any clues!

Best Answer

Will load a player object by id.

Sorry to resurrect this thread,

is there a way to access any player data (in particular the "online" parameter) from a request in C#?

For example, when i send a GetLeaderboardDataRequest():

  foreach (var entry in response.Data)



string mytext= "ONLINE " + entry.isonline.ToString();




Hi Gabriel,

You can do a last seen in cloud code by putting the following in your AuthenticationResponse:


var lastLogin = Spark.getPlayer().getScriptData("lastLogin"); //Get the last login, probably check that it's not null first to prevent errors.
Spark.setScriptData("lastLogin", lastLogin); //The the scriptData before updating the lastLogin variable
Spark.getPlayer().setScriptData("lastLogin", new Date()); //Update the loginData on the player's profile


If the isOnline function can't be relied upon for all platform, i would prefer to use the "lastSeen" field to decide if a message should or should not be send. However, I can't seem to find a way to do so. And I did thoroughly consulted the SparkPlayer page this time.

And the last question on the subject: why does the "online" field stay false when a player is connected from my unity editor when it's made true when connected from the test harness. Even sending correctly 2 custom events does not make the online field go true.

Well I just saw that... And I don't understand how i missed it before...

Sorry for the inconvenience.


Will load a player object by id.

Sounds good. But then my question is how do I get a "myPlayer" object from a playerId?

I have to loop and check which players are online from my array, but i don't see any way to get a player object apart from the Spark.getPlayer() which does not take parameters and return only the active player...

Hi Gabriel

You can check using this:

Sorry, the example is missing (I'll fix that) but it should be

var isOnline = myPlayer.isOnline()


Login to post a comment