diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index c7825f84325..10b7c807afc 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -18,6 +18,7 @@ The version number for this package has increased due to a version update of a r - Fixed ShaderGraph HDRP master preview disappearing for a few seconds when graph is modified [1330289] (https://issuetracker.unity3d.com/issues/shadergraph-hdrp-main-preview-is-invisible-until-moved) - Fixed noise nodes to use a deterministic integer hash, instead of platform dependent floating point hashes [1156544] - Fixed the appearance (wrong text color, and not wrapped) of a warning in Node Settings [1356725] (https://issuetracker.unity3d.com/product/unity/issues/guid/1356725/) + - Fixed the ordering of inputs on a SubGraph node to match the properties on the blackboard of the subgraph itself [1354463] ## [12.0.0] - 2021-01-11 diff --git a/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs b/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs index e0bf6c15416..1467b9b70a9 100644 --- a/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs +++ b/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs @@ -19,7 +19,7 @@ namespace UnityEditor.ShaderGraph { [ExcludeFromPreset] - [ScriptedImporter(28, Extension, -905)] + [ScriptedImporter(29, Extension, -905)] class ShaderSubGraphImporter : ScriptedImporter { public const string Extension = "shadersubgraph"; @@ -281,6 +281,24 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph, ShaderGraphImp } } + // Need to order the properties so that they are in the same order on a subgraph node in a shadergraph + // as they are in the blackboard for the subgraph itself. The (blackboard) categories keep that ordering, + // so traverse those and add those items to the ordered properties list. Needs to be used to set up the + // function _and_ to write out the final asset data so that the function call parameter order matches as well. + var orderedProperties = new List(); + var propertiesList = graph.properties.ToList(); + foreach (var category in graph.categories) + { + foreach (var child in category.Children) + { + var prop = propertiesList.Find(p => p.guid == child.guid); + orderedProperties.Add(prop); + } + } + + // If we are importing an older file that has not had categories generated for it yet, include those now. + orderedProperties.AddRange(graph.properties.Except(orderedProperties)); + // provide top level subgraph function // NOTE: actual concrete precision here shouldn't matter, it's irrelevant when building the subgraph asset registry.ProvideFunction(asset.functionName, asset.subGraphGraphPrecision, ConcretePrecision.Single, sb => @@ -290,7 +308,7 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph, ShaderGraphImp // Generate the arguments... first INPUTS var arguments = new List(); - foreach (var prop in graph.properties) + foreach (var prop in orderedProperties) { // apply fallback to the graph default precision (but don't convert to concrete) // this means "graph switchable" properties will use the precision token @@ -388,7 +406,8 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph, ShaderGraphImp prop.OverrideGuid(namespaceId, nameId + "_Guid_" + i); } } - asset.WriteData(graph.properties, graph.keywords, graph.dropdowns, collector.properties, outputSlots, graph.unsupportedTargets); + + asset.WriteData(orderedProperties, graph.keywords, graph.dropdowns, collector.properties, outputSlots, graph.unsupportedTargets); outputSlots.Dispose(); }