KeyNotFoundException with ShaderGraph

I’m getting several of the following exceptions with some of my shadergraphs if I reimport them. they work fine when running in the editor but I think they are causing my materials to fail in the simulator and output magenta instead. happens in polyspatial 0.5.0 (also happened in 0.4.3) / shadergraph 14.0.9.

[Worker0] KeyNotFoundException: The given key 'UnityEditor.Graphing.SlotReference' was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <f646c7a159d243a7909d5204af0f0c56>:0)
UnityEditor.ShaderGraph.MaterialX.SubGraphAdapter.BuildInstance (UnityEditor.ShaderGraph.AbstractMaterialNode node, UnityEditor.ShaderGraph.MaterialX.MtlxGraphData graph, UnityEditor.ShaderGraph.MaterialX.ExternalEdgeMap externals, UnityEditor.ShaderGraph.MaterialX.SubGraphContext sgContext) (at ./localpackages/com.unity.polyspatial/Editor/ShaderGraphConversion/Adapters/Nodes/Utility/SubGraphAdapter.cs:110)
UnityEditor.ShaderGraph.MaterialX.AdapterMap.ProcessInstance (UnityEditor.ShaderGraph.AbstractMaterialNode node, UnityEditor.ShaderGraph.MaterialX.MtlxGraphData graph, UnityEditor.ShaderGraph.MaterialX.ExternalEdgeMap externals, UnityEditor.ShaderGraph.MaterialX.SubGraphContext sgContext) (at ./localpackages/com.unity.polyspatial/Editor/ShaderGraphConversion/MtlxAdapterMap.cs:63)
UnityEditor.ShaderGraph.MaterialX.MtlxPostProcessor.ProcessGraph (UnityEditor.ShaderGraph.GraphData graphData, System.String filename, System.Boolean skipContext) (at ./localpackages/com.unity.polyspatial/Editor/ShaderGraphConversion/MtlxPostProcessor.cs:89)
UnityEditor.ShaderGraph.MaterialX.MtlxPostProcessor.ProcessFile (System.String assetPath, System.String dstRoot, System.String& filePathNoExtension) (at ./localpackages/com.unity.polyspatial/Editor/ShaderGraphConversion/MtlxPostProcessor.cs:74)
UnityEditor.ShaderGraph.MaterialX.MtlxPostProcessor.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext context) (at ./localpackages/com.unity.polyspatial/Editor/ShaderGraphConversion/MtlxPostProcessor.cs:21)
Unity.PolySpatial.Internals.PolySpatialAssetImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at ./localpackages/com.unity.polyspatial/Editor/PolySpatialAssetImporter.cs:39)
UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at /Users/bokken/build/output/unity/unity/Modules/AssetPipelineEditor/Public/ScriptedImporter.cs:25)

i moved the package to a local directory so that I could modify it to see what failing slots were and they do all exist.

Hello! Could you submit a bug report that reproduces this and let me know the incident number (IN-#####)? It should be sufficient just to include the top-level shader graphs and all its subgraphs (so that importing the top-level shader graph causes the error).

Basically, it looks like we’re not handling one of the outputs of a node within the subgraph that’s connected to a subgraph output, but I can’t tell which one without seeing the actual shader.

Here is the incident number
IN-60093

1 Like

Thanks! That was a great illustration of the issue. It looks like the problem lies with having multiple instances of the same input property in a subgraph (v_color, in this case). We’ll add a fix for that, but in the meantime you can work around it by having a single instance of the property with multiple output connections.

1 Like

I believe I’ve encountered the same issue, although for me it produced a logically incorrect shader graph instead of throwing any errors or outputting an unreadable shader.

I submitted IN-60200 with a repro (before finding this thread). The suggested workaround appears to be working for me though.

1 Like