diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 6894efce5cf..1306a52cdf3 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -134,6 +134,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed a serialization bug wrt PVT property flags when using subgraphs. This fixes SRP batcher compatibility. - Fixed an incorrect direction transform from view to world space [1365186] - Fixed the appearance (wrong text color, and not wrapped) of a warning in Node Settings [1365780] +- Fixed the ordering of inputs on a SubGraph node to match the properties on the blackboard of the subgraph itself [1366052] ## [11.0.0] - 2020-10-21 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(); }