Skip to content
1 change: 1 addition & 0 deletions com.unity.shadergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed a bug where adding a HDRP Master Node to a Shader Graph would softlock the Shader Graph.
- Fixed a bug where shaders fail to compile due to `#pragma target` generation when your system locale uses commas instead of periods.
- Fixed a compilation error when using Hybrid Renderer due to incorrect positioning of macros.
- Fixed a bug where the `Create Node Menu` lagged on load. Entries are now only generated when property, keyword, or subgraph changes are detected. [1209567](https://issuetracker.unity3d.com/issues/shadergraph-opening-node-search-window-is-unnecessarily-slow).
- Fixed a bug with the `Transform` node where converting from `Absolute World` space in a sub graph causes invalid subscript errors. [1190813](https://issuetracker.unity3d.com/issues/shadergraph-invalid-subscript-errors-are-thrown-when-connecting-a-subgraph-with-transform-node-with-unlit-master-node)
- Fixed a bug where the `Position` node would change coordinate spaces from `World` to `Absolute World` when shaders recompile. [1184617](https://issuetracker.unity3d.com/product/unity/issues/guid/1184617/)
- Fixed a bug where instanced shaders wouldn't compile on PS4.
Expand Down
61 changes: 41 additions & 20 deletions com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SearchWindowProvider : ScriptableObject
public bool nodeNeedsRepositioning { get; set; }
public SlotReference targetSlotReference { get; internal set; }
public Vector2 targetPosition { get; internal set; }
public bool regenerateEntries { get; set; }
private const string k_HiddenFolderName = "Hidden";

public void Initialize(EditorWindow editorWindow, GraphData graph, GraphView graphView)
Expand All @@ -54,30 +55,26 @@ void OnDestroy()
m_Icon = null;
}
}

List<int> m_Ids;
List<ISlot> m_Slots = new List<ISlot>();

public void GenerateNodeEntries()
{
// First build up temporary data structure containing group & title as an array of strings (the last one is the actual title) and associated node type.
List<NodeEntry> nodeEntries = new List<NodeEntry>();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
var nodeEntries = new List<NodeEntry>();
foreach (var type in TypeCache.GetTypesDerivedFrom<AbstractMaterialNode>())
{
foreach (var type in assembly.GetTypesOrNothing())
if ((!type.IsClass || type.IsAbstract)
|| type == typeof(PropertyNode)
|| type == typeof(KeywordNode)
|| type == typeof(SubGraphNode))
continue;

if (type.GetCustomAttributes(typeof(TitleAttribute), false) is TitleAttribute[] attrs && attrs.Length > 0)
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode)))
&& type != typeof(PropertyNode)
&& type != typeof(KeywordNode)
&& type != typeof(SubGraphNode))
{
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[];
if (attrs != null && attrs.Length > 0)
{
var node = (AbstractMaterialNode)Activator.CreateInstance(type);
AddEntries(node, attrs[0].title, nodeEntries);
}
}
var node = (AbstractMaterialNode) Activator.CreateInstance(type);
AddEntries(node, attrs[0].title, nodeEntries);
}
}

Expand All @@ -86,7 +83,7 @@ public void GenerateNodeEntries()
var asset = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(AssetDatabase.GUIDToAssetPath(guid));
var node = new SubGraphNode { asset = asset };
var title = asset.path.Split('/').ToList();

if (asset.descendents.Contains(m_Graph.assetGuid) || asset.assetGuid == m_Graph.assetGuid)
{
continue;
Expand Down Expand Up @@ -206,8 +203,11 @@ class SearcherProvider : SearchWindowProvider
{
public Searcher.Searcher LoadSearchWindow()
{
GenerateNodeEntries();

if (regenerateEntries)
{
GenerateNodeEntries();
regenerateEntries = false;
}
//create empty root for searcher tree
var root = new List<SearcherItem>();
var dummyEntry = new NodeEntry();
Expand Down Expand Up @@ -262,7 +262,7 @@ public bool OnSearcherSelectEntry(SearcherItem entry, Vector2 screenMousePositio
return false;

var nodeEntry = (entry as SearchNodeItem).NodeGUID;
var node = nodeEntry.node;
var node = CopyNodeForGraph(nodeEntry.node);

var drawState = node.drawState;

Expand Down Expand Up @@ -293,6 +293,27 @@ public bool OnSearcherSelectEntry(SearcherItem entry, Vector2 screenMousePositio

return true;
}
public AbstractMaterialNode CopyNodeForGraph(AbstractMaterialNode oldNode)
{
var newNode = (AbstractMaterialNode)Activator.CreateInstance(oldNode.GetType());
if (newNode is SubGraphNode subgraphNode)
{
subgraphNode.asset = ((SubGraphNode)oldNode).asset;
}
else if(newNode is PropertyNode propertyNode)
{
propertyNode.owner = m_Graph;
propertyNode.propertyGuid = ((PropertyNode)oldNode).propertyGuid;
propertyNode.owner = null;
}
else if(newNode is KeywordNode keywordNode)
{
keywordNode.owner = m_Graph;
keywordNode.keywordGuid = ((KeywordNode)oldNode).keywordGuid;
keywordNode.owner = null;
}
return newNode;
}
}

}
4 changes: 4 additions & 0 deletions com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage
m_SearchWindowProvider = ScriptableObject.CreateInstance<SearcherProvider>();
m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView);
m_GraphView.nodeCreationRequest = NodeCreationRequest;
//regenerate entries when graph view is refocused, to propogate subgraph changes
m_GraphView.RegisterCallback<FocusInEvent>( evt => { m_SearchWindowProvider.regenerateEntries = true; });

m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider, editorWindow);

Expand Down Expand Up @@ -562,6 +564,8 @@ public void HandleGraphChanges()
}

previewManager.RenderPreviews();
if(m_Graph.addedInputs.Count() > 0 || m_Graph.removedInputs.Count() > 0)
m_SearchWindowProvider.regenerateEntries = true;
m_BlackboardProvider.HandleGraphChanges();
m_GroupHashSet.Clear();

Expand Down