From cf65c442de6fbc733e7732b16bc10a8d708d8ea3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 17 Apr 2026 18:51:50 +0200 Subject: [PATCH] Add `AutoAttachDebugPreviewActor` for Behavior Tree editor --- .../Editor/Windows/Assets/BehaviorTreeWindow.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Windows/Assets/BehaviorTreeWindow.cs b/Source/Editor/Windows/Assets/BehaviorTreeWindow.cs index 03ba26fc8..1317300c3 100644 --- a/Source/Editor/Windows/Assets/BehaviorTreeWindow.cs +++ b/Source/Editor/Windows/Assets/BehaviorTreeWindow.cs @@ -509,10 +509,25 @@ namespace FlaxEditor.Windows.Assets // Check if don't have valid behavior picked if (!_behaviorPicker.Value) { - // Try to reassign the debug behavior var id = _cachedBehaviorId; + if (id == Guid.Empty && Editor.IsPlayMode && Editor.Options.Options.General.AutoAttachDebugPreviewActor) + { + // Auto-attach preview + var behaviorTree = Asset; + var behaviors = Level.GetScripts(); + foreach (var behavior in behaviors) + { + if (behavior.Tree == behaviorTree && + behavior.IsEnabledInHierarchy) + { + id = behavior.ID; + break; + } + } + } if (id != Guid.Empty) { + // Try to reassign the debug behavior var obj = FlaxEngine.Object.TryFind(ref id); if (obj && obj.Tree == Asset) _behaviorPicker.Value = obj;