Skip to content

Commit f56ee7a

Browse files
🔧 Bugfixes
1 parent 58cef51 commit f56ee7a

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Scripts/Items/GameObjectItemBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ protected virtual void Init()
112112

113113
if (Root == null)
114114
{
115-
var parentQuadtreeRoot = (IQuadtreeRoot<TItem, TNode>)GetComponentInParent<QuadtreeMonoRoot<GameObjectItem>>();
116-
if ((bool)parentQuadtreeRoot?.Initialized)
117-
Root = parentQuadtreeRoot;
115+
if (TryGetComponent(out GameObjectRootNode quadtreeRoot) && quadtreeRoot.Initialized)
116+
{
117+
Root = (IQuadtreeRoot<TItem, TNode>)quadtreeRoot;
118+
}
118119
}
119120

120121
if (Root != null)

Scripts/NodeBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public void DrawBounds(bool displayNumberOfItems = false)
410410

411411
Gizmos.DrawWireCube(Bounds.center, Bounds.size);
412412
foreach (var subNode in SubNodes)
413-
subNode.DrawBounds();
413+
subNode.DrawBounds(displayNumberOfItems);
414414
}
415415
}
416416
}

Scripts/QuadtreeMonoRoot.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ protected void OnDrawGizmos()
3636
/// <summary>
3737
/// Root node containing all items and sub-nodes.
3838
/// </summary>
39-
protected QuadtreeRoot<TItem, Node<TItem>> TreeRoot;
39+
protected QuadtreeRoot<TItem, Node<TItem>> TreeRoot = null;
4040

41-
public bool Initialized => (bool)TreeRoot?.Initialized;
41+
public bool Initialized => TreeRoot != null && TreeRoot.Initialized;
4242

4343
public Node<TItem> CurrentRootNode => TreeRoot.CurrentRootNode;
4444

@@ -75,17 +75,17 @@ protected void Init()
7575
}
7676

7777
// send a message to children that the tree root has been initialized
78-
BroadcastMessage("QuadTree_Root_Initialized", this);
78+
BroadcastMessage("QuadTree_Root_Initialized", this, SendMessageOptions.DontRequireReceiver);
7979
}
8080

8181
/// <summary>
8282
/// Displays Quadtree node boundaries.
8383
/// </summary>
8484
///
8585
/// <seealso cref="INode{TItem, TNode}.DrawBounds(bool)"/>
86-
protected void DrawBounds(bool displayNumberOfItems = false)
86+
protected void DrawBounds()
8787
{
88-
TreeRoot?.CurrentRootNode.DrawBounds(displayNumberOfItems);
88+
TreeRoot?.CurrentRootNode.DrawBounds(DisplayNumberOfItemsInGizmos);
8989
}
9090

9191
public void Insert(TItem item) => TreeRoot.Insert(item);

0 commit comments

Comments
 (0)