{"action":"created","issue":{"url":"https://api.github.com/repos/googleanalytics/google-analytics-plugin-for-unity/issues/58","labels_url":"https://api.github.com/repos/googleanalytics/google-analytics-plugin-for-unity/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/googleanalytics/google-analytics-plugin-for-unity/issues/58/comments","events_url":"https://api.github.com/repos/googleanalytics/google-analytics-plugin-for-unity/issues/58/events","html_url":"https://github.com/googleanalytics/google-analytics-plugin-for-unity/issues/58","id":100456160,"number":58,"title":"Null Reference After a couple of minutes into Game","user":{"login":"sfratini","id":10799414,"avatar_url":"https://avatars.githubusercontent.com/u/10799414?v=3","gravatar_id":"","url":"https://api.github.com/users/sfratini","html_url":"https://github.com/sfratini","followers_url":"https://api.github.com/users/sfratini/followers","following_url":"https://api.github.com/users/sfratini/following{/other_user}","gists_url":"https://api.github.com/users/sfratini/gists{/gist_id}","starred_url":"https://api.github.com/users/sfratini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfratini/subscriptions","organizations_url":"https://api.github.com/users/sfratini/orgs","repos_url":"https://api.github.com/users/sfratini/repos","events_url":"https://api.github.com/users/sfratini/events{/privacy}","received_events_url":"https://api.github.com/users/sfratini/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-12T03:18:55Z","updated_at":"2015-09-22T07:24:53Z","closed_at":null,"body":"Hi! After a couple of minutes of using the Game in Unity, the Editor shows that the console is being filled (999+) with Null references in the GoogleAnalyticsMPV3 class in just a couple of seconds. Particularly, this line:\r\n\r\nGoogleAnalyticsV3.getInstance().StartCoroutine(this.HandleWWW(new WWW(newUrl)));\r\n\r\nSome debugging made me realize the instance was null, therefore the error. I solved it replacing the code with:\r\n\r\ntry {\r\n\t\tGoogleAnalyticsV3.getInstance().StartCoroutine(this.HandleWWW(new WWW(newUrl)));\r\n\t} catch (Exception e){\t\t\t\r\n\t}\r\n\r\nTo avoid filling the log and replace the getInstance code with this:\r\n\r\n    if (instance == null)\r\n\t\tinstance = this;\r\n    return instance;\r\n\r\nBefore, if would just return the instance and since it was null, I was getting the error. Will this affect my reports in any way?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/googleanalytics/google-analytics-plugin-for-unity/issues/comments/142201292","html_url":"https://github.com/googleanalytics/google-analytics-plugin-for-unity/issues/58#issuecomment-142201292","issue_url":"https://api.github.com/repos/googleanalytics/google-analytics-plugin-for-unity/issues/58","id":142201292,"user":{"login":"sebastienalcamo","id":11536528,"avatar_url":"https://avatars.githubusercontent.com/u/11536528?v=3","gravatar_id":"","url":"https://api.github.com/users/sebastienalcamo","html_url":"https://github.com/sebastienalcamo","followers_url":"https://api.github.com/users/sebastienalcamo/followers","following_url":"https://api.github.com/users/sebastienalcamo/following{/other_user}","gists_url":"https://api.github.com/users/sebastienalcamo/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastienalcamo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastienalcamo/subscriptions","organizations_url":"https://api.github.com/users/sebastienalcamo/orgs","repos_url":"https://api.github.com/users/sebastienalcamo/repos","events_url":"https://api.github.com/users/sebastienalcamo/events{/privacy}","received_events_url":"https://api.github.com/users/sebastienalcamo/received_events","type":"User","site_admin":false},"created_at":"2015-09-22T07:24:53Z","updated_at":"2015-09-22T07:24:53Z","body":"The question we need to ask ourselves is \"**How the hell the GoogleAnalyticsV3 instance could be null ?**\"\r\n\r\nThe root cause of this problem is the Unity's hotswapping.\r\nIf we edit a script and if we focus in Unity editor while the application is running, there would be a process of serialization & deserialization. Any serializable data type will get back to its initial value. By contrast, any non-serializable singleton instance will be reset to null, like the GoogleAnalyticsV3 one.\r\n\r\nIf you have set GA \"**UncaughtExceptionReporting**\" to true, the plugin will try to log any exceptions thrown. After a hot swap, on the next SendGaHitWithMeasurementProtocol, there will an exception thrown (because GAv3 instance is null, NullReferenceException) that will lead to a new SendGaHitWithMeasurementProtocol that will lead to another exception, etc...\r\n\r\nThis kind of scenario only happens when running the application in Unity editor.\r\nUnity's Hotswapping can't work since we use non-serializable data types."}}