When our game starts we need to fetch data from GameSparks
server as soon has GS is ready. So I'm adding a listener to
GS.GameSparksAvailable that starts downloading levels from GS server. But when
there's no internet connectivity my GameSparksAvailable listener is not called.
So what is the recommended way to test if internet
connection is available when using GS? Use a GS listener or event or parameter
that I don't about or use something like UnityEngine.Network.TestConnection()
public class GameBootstrapper : MonoBehaviour
{
void Start ()
{
GS.GameSparksAvailable += HandleGameSparksAvailable;
}
//not call if no internet connectivity
private void HandleGameSparksAvailable (bool value)
{
//what is meaning of the bool parameter ???
DownloadLevelFromGS ();
GS.GameSparksAvailable -= HandleGameSparksAvailable;
}
private void DownloadLevelFromGS ()
{
...
}
//I don't know when to call this
private void InitDefaultLevel ()
{
...
}
}
Best Answer
S
Shane O'Brien
said
over 6 years ago
The bool is to let you know if GameSparks is available. If you put
void Start ()
{
GS.GameSparksAvailable += HandleGameSparksAvailable;
}
//not call if no internet connectivity
private void HandleGameSparksAvailable (bool value)
{
//what is meaning of the bool parameter ???
Debug.Log(value);
}
You'll see that it's equal to true if you're connected to GameSparks and false if not. It's not required for anything but available if you need it. At the moment you have to check if GameSparks is not available and code around it yourself, but an Offline mode is in the plans in the next 4 weeks or so.
void OnGUI()
{
if (Application.internetReachability != NetworkReachability.NotReachable)
{
// do some stuff
}
else
{
// No connection
}
}
D
Dave Reed
said
over 6 years ago
Hi,
Somewhat related to this, I'm fairly sure we're seeing cases in our project where GameSparks doesn't become 'available' on iOS after a suspend/resume, despite having good internet connectivity (and being available and authenticated before the suspend)
Is there anything we could do or should be doing do in these cases to retry/recheck? (When this happens, another suspend/resume seems to make it become available again)
void OnApplicationPause (bool pause)
{
if(pause)
{
// we are in background
}
else
{
// we are in foreground again.
if (!GS.Available)
{
GS.Reconnect();
}
}
}
I'll have to test this myself, if I find a different solution I'll post back here
C
Christian Gauthier
said
over 6 years ago
Application.internetReachability indicates if the device has wifi ON or not. The Wifi can be ON and still have no internet access. Network.TestConnection() can be use to detect internet access. But since GS tries to open a websocket at startup, it should notify the application when it fails connect to make the game starts in "LOCAL" mode. BTW I still don't know the meaning of bool parameter in GameSparksAvailable listener.
S
Shane O'Brien
said
over 6 years ago
Answer
The bool is to let you know if GameSparks is available. If you put
void Start ()
{
GS.GameSparksAvailable += HandleGameSparksAvailable;
}
//not call if no internet connectivity
private void HandleGameSparksAvailable (bool value)
{
//what is meaning of the bool parameter ???
Debug.Log(value);
}
You'll see that it's equal to true if you're connected to GameSparks and false if not. It's not required for anything but available if you need it. At the moment you have to check if GameSparks is not available and code around it yourself, but an Offline mode is in the plans in the next 4 weeks or so.
1 person likes this
B
Baris Tumerkan
said
about 6 years ago
Does this mean, if the connection is lost, the GS.GameSparksAvailable callback should be called? This doesn't seem to work now. This is not necessarily needed, but it would be nice to have
L
Luis Vieira
said
about 6 years ago
Hi What happens to this?? if the connection is lost, the GS.GameSparksAvailable callback should be called? Thanks this topics is very helpfull
Customer Support
said
about 6 years ago
Hi Luis,
Actually since this topic was created we have added a new function to the Unity SDK called SetDurable, this will allow you to queue up requests if a connection is lost.
Once the connection is re-established, the relevant requests will be sent.
Hope this helps out.
Thanks,
Oisin
S
Stephane Cros
said
almost 6 years ago
Hi Oisin,
I am testing SetDurable on a LogEventRequest with a Send completion handler that writes some Debug.Log text depending on the response.HasErrors.
With internet connection, that LogEventRequest will generate on the console the "GS: SEND:" info followed by the "GS: RECV:" info and my "Event Request OK" text.
With no internet connection, the console returns the "GS: SEND:" info followed by my "Event Request ERROR!!!" message,
and when the connection comes back, the request is sent as a second attempt (SetDurable), the console returns the "GS: SEND:" info, followed by the "GS: RECV:" info but none of my texts "Event Request OK" nor "Event Request ERROR".
Can you please confirm whether the Send completion handler is supposed to be executed on a SetDurable request when triggered by a re-established connection?
Thanks,
Stephane
Customer Support
said
over 5 years ago
Hey Stephane,
This is the correct behavior, but you can attach your own callback to any of this event handlers if you want to control what happens when the game reconnects.
-Sean
D
Dan Gal
said
about 4 years ago
void Start (){
GS.GameSparksAvailable += HandleGameSparksAvailable;}//not call if no internet connectivityprivatevoid HandleGameSparksAvailable (boolvalue){//what is meaning of the bool parameter ???
Debug.Log(value);}
This does not work
When the application is launched with no internet, HandleGameSparksAvailable is never called.
1 person likes this
C
Christopher Bonnell
said
about 4 years ago
Dan, GS.GameSparksAvailable is a callback that only triggers when GameSparks becomes available. If you have no internet, GameSparks won't be available, and therefore the callback (HandleGameSparksAvailable) won't be triggered. If you need something to run whether connected to GameSparks or not, you need to isolate it and call it manually on the even that GameSparks is unable to connect. In my case, I ran a Coroutine that after 5 seconds, considered itself timed out (and subsequently removed the DefaultPlatform Component to stop it from constantly sending a connecting request every second)..
D
Domen Grabec
said
almost 4 years ago
IMHO the API is a bit confusing. If GameSparksAvailable does not trigger when the connection is lost why does the method signature contain a bool that holds "isAvailable" information. Shouldn't the method signature be:
Action GameSparksOnAvailable
instead of
Action<bool> GameSparksAvailable
C
Christopher Bonnell
said
almost 4 years ago
Because when you finally connect to GameSparks, the callback is triggered, and then when you subsequently get disconnected, it will pass false rather than true. I was previously talking about the case where you never connect to GS in the first place.
Christian Gauthier
When our game starts we need to fetch data from GameSparks server as soon has GS is ready. So I'm adding a listener to GS.GameSparksAvailable that starts downloading levels from GS server. But when there's no internet connectivity my GameSparksAvailable listener is not called.
So what is the recommended way to test if internet connection is available when using GS? Use a GS listener or event or parameter that I don't about or use something like UnityEngine.Network.TestConnection()
The bool is to let you know if GameSparks is available. If you put
You'll see that it's equal to true if you're connected to GameSparks and false if not. It's not required for anything but available if you need it. At the moment you have to check if GameSparks is not available and code around it yourself, but an Offline mode is in the plans in the next 4 weeks or so.
1 person has this question
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstShane O'Brien
Unity has some built in functionality in this regard with it's Application.internetReachability and NetworkReachability.
Dave Reed
Somewhat related to this, I'm fairly sure we're seeing cases in our project where GameSparks doesn't become 'available' on iOS after a suspend/resume, despite having good internet connectivity (and being available and authenticated before the suspend)
Is there anything we could do or should be doing do in these cases to retry/recheck? (When this happens, another suspend/resume seems to make it become available again)
1 person likes this
Shane O'Brien
You could possibly try using OnApplicationPause
I'll have to test this myself, if I find a different solution I'll post back here
Christian Gauthier
Application.internetReachability indicates if the device has wifi ON or not. The Wifi can be ON and still have no internet access. Network.TestConnection() can be use to detect internet access. But since GS tries to open a websocket at startup, it should notify the application when it fails connect to make the game starts in "LOCAL" mode. BTW I still don't know the meaning of bool parameter in GameSparksAvailable listener.
Shane O'Brien
The bool is to let you know if GameSparks is available. If you put
You'll see that it's equal to true if you're connected to GameSparks and false if not. It's not required for anything but available if you need it. At the moment you have to check if GameSparks is not available and code around it yourself, but an Offline mode is in the plans in the next 4 weeks or so.
1 person likes this
Baris Tumerkan
Does this mean, if the connection is lost, the GS.GameSparksAvailable callback should be called? This doesn't seem to work now. This is not necessarily needed, but it would be nice to have
Luis Vieira
Hi What happens to this?? if the connection is lost, the GS.GameSparksAvailable callback should be called? Thanks this topics is very helpfull
Customer Support
Hi Luis,
Actually since this topic was created we have added a new function to the Unity SDK called SetDurable, this will allow you to queue up requests if a connection is lost.
Once the connection is re-established, the relevant requests will be sent.
Hope this helps out.
Thanks,
Oisin
Stephane Cros
Hi Oisin,
I am testing SetDurable on a LogEventRequest with a Send completion handler that writes some Debug.Log text depending on the response.HasErrors.
With internet connection, that LogEventRequest will generate on the console the "GS: SEND:" info followed by the "GS: RECV:" info and my "Event Request OK" text.
With no internet connection, the console returns the "GS: SEND:" info followed by my "Event Request ERROR!!!" message,
and when the connection comes back, the request is sent as a second attempt (SetDurable), the console returns the "GS: SEND:" info, followed by the "GS: RECV:" info but none of my texts "Event Request OK" nor "Event Request ERROR".
Can you please confirm whether the Send completion handler is supposed to be executed on a SetDurable request when triggered by a re-established connection?
Thanks,
Stephane
Customer Support
This is the correct behavior, but you can attach your own callback to any of this event handlers if you want to control what happens when the game reconnects.
-Sean
Dan Gal
void Start () { GS.GameSparksAvailable += HandleGameSparksAvailable; } //not call if no internet connectivity private void HandleGameSparksAvailable (bool value) { //what is meaning of the bool parameter ??? Debug.Log(value); }
This does not work
When the application is launched with no internet, HandleGameSparksAvailable is never called.
1 person likes this
Christopher Bonnell
Dan, GS.GameSparksAvailable is a callback that only triggers when GameSparks becomes available. If you have no internet, GameSparks won't be available, and therefore the callback (HandleGameSparksAvailable) won't be triggered. If you need something to run whether connected to GameSparks or not, you need to isolate it and call it manually on the even that GameSparks is unable to connect. In my case, I ran a Coroutine that after 5 seconds, considered itself timed out (and subsequently removed the DefaultPlatform Component to stop it from constantly sending a connecting request every second)..
Domen Grabec
IMHO the API is a bit confusing. If GameSparksAvailable does not trigger when the connection is lost why does the method signature contain a bool that holds "isAvailable" information. Shouldn't the method signature be:
Action GameSparksOnAvailable
instead of
Action<bool> GameSparksAvailable
Christopher Bonnell
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2486 topics