Script Compilation Fails for project with Google Play Games plugin

We spent a week chasing ghosts/fixing crashes on start-up when non-programmers synced our project because of this issue, and I wanted to write up the bug and suggest a temporary workaround for anyone else who sees it.

In Unity 2017.1.0f3, on a project with the Google Play Games plugin, script changes made while Unity is not running don’t trigger a compile. At startup, we saw this stack trace:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Scripting.ScriptCompilation.EditorCompilation.DirtyScript (System.String path) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:88)
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface.DirtyScript (System.String path) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:44)
UnityEditor.AssetDatabase:Refresh()
GooglePlayGames.Editor.GPGSUpgrader:.cctor() (at Assets/GooglePlayGames/Editor/GPGSUpgrader.cs:110)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes()

If you hit play, it’ll run the most recently compiled thing, which meant features looked half-working, or crashed completely if assets and scripts diverged enough – artists and designers were hit hardest, since they didn’t edit scripts. The only way to get it to compile was to tab out of Unity, change some C# file, and tab back.

Our workaround for now is to comment out line 110 of GPGSUpgrader.cs, so it doesn’t call AssetDatabase.Refresh(). But, it looks like the general problem here is that it’s not safe to call AssetDatabase.Refresh() from UnityEditor.EditorAssemblies: ProcessInitializeOnLoadAttributes(). Based on ILSpy output, it’s because EditorCompilation.DirtyScript() references allScripts, which is initialized to null and only set by EditorCompilation.SetAllScripts().

Hope this helps save some headaches until a fix lands.

1 Like

Thank you so much! My workaround was to find a debug log output, add a space at the end and hit recompile.
It also took a while until I realised why my code changes are not applied…

Glad to help!

FYI, Support says it’s fixed in 2017.1.1p1, but it’ll be a while before I have time for another update to check and see.

Well, working with 2019.3.2f1, and that same error is still there. Commenting out that line (102 currently) still fixes it.

1 Like

I keep returning to this thread so I think I should drop a comment there too.

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.GameObjectInspector.ClearPreviewCache () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:211)
UnityEditor.GameObjectInspector.ReloadPreviewInstances () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:581)
UnityEditor.GameObjectInspector.OnForceReloadInspector () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:206)
UnityEditor.AssetDatabase:Refresh()
GooglePlayGames.Editor.GPGSUpgrader:.cctor() (at Assets/GooglePlayGames/Editor/GPGSUpgrader.cs:104)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type[]) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:114)

There’s that line @104 that comes up so I’ll look into the hotfix. I must say that this type of correction feels really sloppy.
Unity 19.4.17f1