Search Unity

Script Compilation Fails for project with Google Play Games plugin

Discussion in 'Editor & General Support' started by demi_owen, Sep 8, 2017.

  1. demi_owen

    demi_owen

    Joined:
    Jun 29, 2017
    Posts:
    2
    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:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEditor.Scripting.ScriptCompilation.EditorCompilation.DirtyScript (System.String path) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:88)
    3. UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface.DirtyScript (System.String path) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:44)
    4. UnityEditor.AssetDatabase:Refresh()
    5. GooglePlayGames.Editor.GPGSUpgrader:.cctor() (at Assets/GooglePlayGames/Editor/GPGSUpgrader.cs:110)
    6. 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.
     
    URPian likes this.
  2. chriser

    chriser

    Joined:
    Jan 14, 2015
    Posts:
    2
    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...
     
  3. demi_owen

    demi_owen

    Joined:
    Jun 29, 2017
    Posts:
    2
    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.
     
  4. Dawdlebird

    Dawdlebird

    Joined:
    Apr 22, 2013
    Posts:
    88
    Well, working with 2019.3.2f1, and that same error is still there. Commenting out that line (102 currently) still fixes it.
     
    URPian likes this.
  5. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    I keep returning to this thread so I think I should drop a comment there too.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEditor.GameObjectInspector.ClearPreviewCache () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:211)
    3. UnityEditor.GameObjectInspector.ReloadPreviewInstances () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:581)
    4. UnityEditor.GameObjectInspector.OnForceReloadInspector () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:206)
    5. UnityEditor.AssetDatabase:Refresh()
    6. GooglePlayGames.Editor.GPGSUpgrader:.cctor() (at Assets/GooglePlayGames/Editor/GPGSUpgrader.cs:104)
    7. 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