Utilities class - Expand to whole Unity please

The Utilities class in the Unity.Services.RemoteConfig namespace has a single method that is used for checking internet connection, namely CheckForInternetConnection. Is there any particular reason why this is only available in this namespace and i.e. not in the other UGS namespaces or the whole Unity namespace UnityEngine?

It would be great to have this simple check available everywhere, otherwise people will always look for another option to check internet connection. Some are easier to implement than others, but don't handle errors well etc.

It's available anywhere as long as Unity services package is installed. Namespaces are not about "discovery". In fact, a great IDE makes discovery a non-issue!

You can see I do not have Unity.Services usings on top, but I do have RemoteConfig package installed. Now I can just start typing "Utilities" and the IDE makes good suggestions which I can easily follow along:
8341605--1097031--upload_2022-8-6_10-32-10.png

And there we have it (the using statement is added automatically, I never manually edit using statements anymore, since unused will be removed automatically as well in my setup):
8341605--1097034--upload_2022-8-6_10-33-12.png

I only had to know that this method is in a "Utilities" namespace. If I don't know about that, but know there is a method called "CheckForInternetConnection" I'll search for it:
8341605--1097037--upload_2022-8-6_10-38-42.png

Of course, this isn't Microsoft Visual Studio as it is merely a decent IDE. :p

Btw, this particular method is trivial enough to copy it into your own global namespace if you find it more convenient. I've seen this code snippet on the forums before.

namespace Unity.Services.RemoteConfig
{
    public static class Utilities
    {
        public static bool CheckForInternetConnection()
        {
            try
            {
                using (var client = new WebClient())
                    using (client.OpenRead("http://unity3d.com"))
                        return true;
            }
            catch
            {
                return false;
            }
        }
    }
}

It's slightly pretentious that the entire Internet must be unavailable if unity3d.com happens to be offline. :smile:

1 Like

I know it’s a simple as installing the package or copy/pasting the code, but I guess you didn’t get what I meant in general. Why is it only there? Was there any discussion internally about putting it to a global namespace so it’s available by default without knowing that it’s available in a specific package?

[quote=“CodeSmile”, post:2, topic: 890273]

namespace Unity.Services.RemoteConfig
{
    public static class Utilities
    {
        public static bool CheckForInternetConnection()
        {
            try
            {
                using (var client = new WebClient())
                    using (client.OpenRead("http://unity3d.com"))
                        return true;
            }
            catch
            {
                return false;
            }
        }
    }
}

It’s slightly pretentious that the entire Internet must be unavailable if unity3d.com happens to be offline. :smile:
[/quote]I can’t believe Unity allowed that to pass any sort of review process :frowning:

@MiTschMR

I suggest you ignore that method. The correct Unity approach is to use the following property…

https://docs.unity3d.com/ScriptReference/Application-internetReachability.html

It’s not perfect, but it’s better than the utility method above imo.

1 Like