diff --git a/Core/BehaviourTree.cs b/Core/BehaviourTree.cs index 0bd004b..af97b67 100644 --- a/Core/BehaviourTree.cs +++ b/Core/BehaviourTree.cs @@ -421,6 +421,15 @@ void AddBlackboardAsset() } } + public void OnValidate() + { + var hasNullable = allNodes.Any(node => node == null); + if (hasNullable) + { + allNodes = allNodes.Where(node => node != null).ToArray(); + } + } + [HideInInspector] public Vector2 panPosition = Vector2.zero; diff --git a/Core/Composite.cs b/Core/Composite.cs index 18d3355..fd98813 100644 --- a/Core/Composite.cs +++ b/Core/Composite.cs @@ -1,4 +1,6 @@  +using System.Collections.Generic; +using System.Linq; using UnityEngine; namespace Bonsai.Core @@ -100,5 +102,16 @@ public sealed override int MaxChildCount() return int.MaxValue; } +#if UNITY_EDITOR + + private void OnValidate() + { + var hasNullable = children.Any(child => child == null); + if (hasNullable) + { + children = children.Where(child => child != null).ToArray(); + } + } +#endif } } \ No newline at end of file