Search Unity

Bug Shadergraph error when upgrading from 2022.2.1 to 2022.2.4

Discussion in 'Editor & General Support' started by Toreth, Jan 29, 2023.

  1. Toreth

    Toreth

    Joined:
    Apr 8, 2017
    Posts:
    31
    I have a project that was using Unity 2022.2.1 and I upgraded it to 2022.2.4. Now when I open the project, the Unity Editor constantly scrolls null reference exception errors in the Console. I think they are because some of my materials used a custom shader that I made in Shadergraph that isn't importing correctly. When I open the shader in Shadergraph, it looks fine. But when I try to save it, I get this error

    Code (csharp):
    1. Asset import failed, "Assets/Shaders/Glow.shadergraph" > InvalidOperationException: Failed to add object of type `UniversalMetadata`. Check that the definition is in a file of the same name and that it compiles properly.
    2. UnityEditor.AssetImporters.AssetImportContext.AddObjectToAsset (System.String identifier, UnityEngine.Object obj) (at <c119aa0913a0473185a8287e39c3f563>:0)
    3. UnityEditor.ShaderGraph.ShaderGraphImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at ./Library/PackageCache/com.unity.shadergraph@14.0.5/Editor/Importers/ShaderGraphImporter.cs:239)
    4. UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at <c119aa0913a0473185a8287e39c3f563>:0)
    5. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    6.  
    7. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
     
    Mushakushi, g4ma and crafTDev like this.
  2. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    I get this too!
     
  3. g4ma

    g4ma

    Joined:
    Dec 18, 2018
    Posts:
    32
    Hello!

    This thread should probably get flagged as a bug.

    I get a similar behaviour when trying to save a subgraph asset that went fine in 2022.2.2.

    If ever I open this subgraph in 2022.2.4 the saving process throws with this message :

    System.InvalidOperationException: Failed to add object of type `SubGraphAsset`. Check that the definition is in a file of the same name and that it compiles properly.


    And this callstack :

    Void UnityEditor.ShaderGraph.ShaderSubGraphImporter:OnImportAsset (AssetImportContext)+0x16e at [snip]\PackageCache\com.unity.shadergraph@14.0.5\Editor\Importers\ShaderSubGraphImporter.cs:[116:13-116:68]   C#
    Void UnityEditor.AssetImporters.ScriptedImporter:GenerateAssetData (AssetImportContext)+0x3 at :-1 C#
    Void UnityEditor.AssetDatabase:ImportAsset (String)+0x3 at :-1 C#
    Boolean UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow:SaveAsset ()+0xd8 at [snip]\PackageCache\com.unity.shadergraph@14.0.5\Editor\Drawing\MaterialGraphEditWindow.cs:[620:21-620:53] C#
    Void UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow:<set_graphEditorView>b__25_0 ()+0x1 at [snip]\PackageCache\com.unity.shadergraph@14.0.5\Editor\Drawing\MaterialGraphEditWindow.cs:[89:62-89:73] C#
    [snip]



    I experienced a similar bug through saving of a shader asset (Failed to add object of type `HDMetadata`) and probably others.
     
    Last edited: Feb 3, 2023
  4. Toreth

    Toreth

    Joined:
    Apr 8, 2017
    Posts:
    31
    I changed the thread tag to Bug.
     
  5. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    87
    Yep me too... Did anyone file a but report yet?
     
  6. g4ma

    g4ma

    Joined:
    Dec 18, 2018
    Posts:
    32
    Thanks for the tag!

    I have not figured out yet a minimal repro so no bug report so far.
    It seems linked to HDRP settings broken in some ways.
     
  7. g4ma

    g4ma

    Joined:
    Dec 18, 2018
    Posts:
    32
    It looks like the issue is gone when switching to 2022.2.5, although we could not find any reason for this in the changelog.

    edit: nope, actually could reproduce it on another machine with 2022.2.5.
     
    Last edited: Feb 14, 2023
  8. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    So my fix was to remove URP from project, close the project, reopen and reinstall URP...
     
  9. alloystorm

    alloystorm

    Joined:
    Jul 25, 2019
    Posts:
    88
    Having the same issue.
    Waiting for a proper fix.
     
  10. Toreth

    Toreth

    Joined:
    Apr 8, 2017
    Posts:
    31
    I haven't been able to reproduce the problem on a new project either. One of the other posts say that his solution was removing/recreating the URP assets so maybe this problem only happens if the URP assets had been originally created by a much older version of Unity (which is the case in my project)? I haven't tested that fix myself yet.
     
  11. alloystorm

    alloystorm

    Joined:
    Jul 25, 2019
    Posts:
    88
    I managed to get this working by removing the "Library" folder before changing Unity version.
     
    AdrienVR and BACALL like this.
  12. g4ma

    g4ma

    Joined:
    Dec 18, 2018
    Posts:
    32
    Has anyone tried the 2022.2.6f1 version, as one of the changelog items could be related to it?

    VFX Graph: Fixed an issue to avoid file access as much as possible when new assets are imported. (UUM-21642)
     
  13. Syvies

    Syvies

    Joined:
    May 11, 2020
    Posts:
    1
    I had the error in 2022.2.5f1. I tried changing version to 2022.2.6f1 and I don't see the error message anymore, I think it's fixed indeed.
     
  14. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    87
    Can confirm this worked for me, updating from 2022.2.4f1 to 2022.2.6f1
     
  15. HiddenTess

    HiddenTess

    Joined:
    Jan 7, 2016
    Posts:
    21
    I had some shaders that were working fine in 2022.2.4, and worked fine after upgrading to 2022.2.7, but after changing the name of my project and reconstructing my Library, I'm now getting this error, too. Weirdly, I can open the shaders in the graph editor just fine.
     
  16. HiddenTess

    HiddenTess

    Joined:
    Jan 7, 2016
    Posts:
    21
    I managed to fix my problem. I had to reimport both the Universal RP and Shader Graph packages. Weird.
     
  17. NibbleByteSSG

    NibbleByteSSG

    Joined:
    Jan 7, 2020
    Posts:
    34
    This also happened to us on our build machine. Every time we did a clean build (with no Library) there were shaders failing. The weird part was that it happened consistently with one machine, only when run by Jenkins (works when run manually from cmd) in batch mode. It used to happen on some other machines but it magically disappeared. After a few days of pulling our hairs, we upgraded the PC in question from Windows 10 to Windows 11 and it got fixed magically.

    While debugging we noticed that some script files from the packages are not imported properly, causing the shaders to fail to compile. These files are:
    Packages/com.unity.shadergraph/Editor/Data/SubGraph/SubGraphAsset.cs
    Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalMetadata.cs
    Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/AssetVersion.cs


    You can notice this happening in the logs, when those files are imported. When broken it gets different artifact id.
    This is how a working version should look:
    Code (CSharp):
    1. Start importing Packages/com.unity.shadergraph/Editor/Data/SubGraph/SubGraphAsset.cs using Guid(f28ce979dc22145fd8160e458f72f65d) Importer(-1,00000000000000000000000000000000)  -> (artifact id: '725f03f5101e0bbd3d3c2db2e3431786') in 0.001721 seconds
    This is how a broken version looks:
    Code (CSharp):
    1. Start importing Packages/com.unity.shadergraph/Editor/Data/SubGraph/SubGraphAsset.cs using Guid(f28ce979dc22145fd8160e458f72f65d) Importer(-1,00000000000000000000000000000000)  -> (artifact id: '91fbd975371c2af3c0bc8d4231d22c1c') in 0.001852 seconds
    Note the produced artifactid 91fbd975371c2af3c0bc8d4231d22c1c. You can confirm this with the "Window/Analysis/Import Activity" window. These ids should be the same for everybody, not just our setup.
    I've tried reimporting those files before the build starts - it didn't work as Unity produced the same broken artefact id. Tried embedding the packages, again it didn't work.
    If you open the editor and reimport the scripts by hand, they get fixed. But this is not an option for a build machine.

    This didn't happen with Unity 2021.3.x. It started when we migrated to 2022.3.22f
    Cache was disabled during the tests.
    Happened with almost empty project as well - it affects the packages, it is unaffacted by the assets.
     
    Last edited: Apr 9, 2024