Skip to content

Commit d99d092

Browse files
authored
Merge pull request #117 from FreshlyBrewedCode/field-drawer-fix
Fix inconsistent field drawer behavior
2 parents d765749 + 4b620ec commit d99d092

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseNodeView.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,13 @@ protected void AddInputContainer()
556556

557557
protected virtual void DrawDefaultInspector(bool fromInspector = false)
558558
{
559-
var fields = nodeTarget.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
559+
var fields = nodeTarget.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
560+
// Filter fields from the BaseNode type since we are only interested in user-defined fields
561+
// (better than BindingFlags.DeclaredOnly because we keep any inherited user-defined fields)
562+
.Where(f => f.DeclaringType != typeof(BaseNode))
563+
// Order by MetadataToken to sync the order with the port order (make sure FieldDrawers are next to the correct port)
564+
//TODO: Also consider custom port order
565+
.OrderBy(f => f.MetadataToken);
560566

561567
foreach (var field in fields)
562568
{
@@ -722,6 +728,11 @@ protected VisualElement AddControlField(FieldInfo field, string label = null, bo
722728
controlsContainer.Add(element);
723729
}
724730
}
731+
else
732+
{
733+
// Make sure we create an empty placeholder if FieldFactory can not provide a drawer
734+
if (showInputDrawer) AddEmptyField(field, false);
735+
}
725736

726737
var visibleCondition = field.GetCustomAttribute(typeof(VisibleIf)) as VisibleIf;
727738
if (visibleCondition != null)

0 commit comments

Comments
 (0)