diff --git a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs index 882a38100..d7ab6d12b 100644 --- a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs +++ b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs @@ -350,14 +350,14 @@ namespace FlaxEditor.CustomEditors.Editors } else { - if (PresenterContext is PropertiesWindow) + if (PresenterContext is PropertiesWindow || PresenterContext == null) _linkedTreeNode = Editor.Instance.Scene.GetActorNode(actor).TreeNode; else if (PresenterContext is PrefabWindow prefabWindow) _linkedTreeNode = prefabWindow.Graph.Root.Find(actor).TreeNode; if (_linkedTreeNode != null) { _linkedTreeNode.ExpandAllParents(); - if (PresenterContext is PropertiesWindow) + if (PresenterContext is PropertiesWindow || PresenterContext == null) Editor.Instance.Windows.SceneWin.SceneTreePanel.ScrollViewTo(_linkedTreeNode, true); else if (PresenterContext is PrefabWindow prefabWindow) (prefabWindow.Tree.Parent as Panel).ScrollViewTo(_linkedTreeNode, true); @@ -427,7 +427,7 @@ namespace FlaxEditor.CustomEditors.Editors private void Select(Actor actor) { - if (PresenterContext is PropertiesWindow) + if (PresenterContext is PropertiesWindow || PresenterContext == null) Editor.Instance.SceneEditing.Select(actor); else if (PresenterContext is PrefabWindow prefabWindow) prefabWindow.Select(prefabWindow.Graph.Root.Find(actor)); diff --git a/Source/Editor/Options/GeneralOptions.cs b/Source/Editor/Options/GeneralOptions.cs index f0abed8a0..59fac7a63 100644 --- a/Source/Editor/Options/GeneralOptions.cs +++ b/Source/Editor/Options/GeneralOptions.cs @@ -162,6 +162,13 @@ namespace FlaxEditor.Options [EditorDisplay("Content"), EditorOrder(550)] public bool UseAssetImportPathRelative { get; set; } = true; + /// + /// If checked, editor windows will try to automatically attach to the first found valid actor for preview. For example, Animation Graph window will pick the first matching instance to preview. + /// + [DefaultValue(false)] + [EditorDisplay("Content"), EditorOrder(550)] + public bool AutoAttachDebugPreviewActor { get; set; } = false; + /// /// Gets or sets a value indicating whether perform automatic CSG rebuild on brush change. /// diff --git a/Source/Editor/Windows/Assets/AnimationGraphWindow.cs b/Source/Editor/Windows/Assets/AnimationGraphWindow.cs index 093938eba..7e809d968 100644 --- a/Source/Editor/Windows/Assets/AnimationGraphWindow.cs +++ b/Source/Editor/Windows/Assets/AnimationGraphWindow.cs @@ -415,8 +415,24 @@ namespace FlaxEditor.Windows.Assets /// public override unsafe void OnUpdate() { - // Extract animations playback state from the events tracing + // Auto-attach preview var debugActor = _debugPicker.Value as AnimatedModel; + if (!debugActor && Editor.IsPlayMode && Editor.Options.Options.General.AutoAttachDebugPreviewActor) + { + var animationGraph = OriginalAsset; + var animatedModels = Level.GetActors(); + foreach (var animatedModel in animatedModels) + { + if (animatedModel.AnimationGraph == animationGraph && + animatedModel.IsActiveInHierarchy) + { + _debugPicker.Value = animatedModel; + break; + } + } + } + + // Extract animations playback state from the events tracing if (debugActor == null) debugActor = _preview.PreviewActor; if (debugActor != null)