diff --git a/Source/Engine/AI/Behavior.h b/Source/Engine/AI/Behavior.h index b1c39ffc6..cdad7331b 100644 --- a/Source/Engine/AI/Behavior.h +++ b/Source/Engine/AI/Behavior.h @@ -57,6 +57,15 @@ public: { return &_knowledge; } + + /// + /// Gets the blackboard of a given type. + /// + template + FORCE_INLINE T* GetBlackboard() + { + return _knowledge.GetBlackboard(); + } /// /// Gets the last behavior tree execution result. diff --git a/Source/Engine/AI/BehaviorKnowledge.h b/Source/Engine/AI/BehaviorKnowledge.h index cd5aeab80..80f04b6e9 100644 --- a/Source/Engine/AI/BehaviorKnowledge.h +++ b/Source/Engine/AI/BehaviorKnowledge.h @@ -124,6 +124,19 @@ public: RemoveGoal(T::TypeInitializer); } + /// + /// Gets the blackboard of a given type. + /// + template + FORCE_INLINE T* GetBlackboard() + { + auto* structure = Blackboard.AsStructure(); + if (structure) + return structure; + + return Blackboard.AsObject(T::TypeInitializer); + } + public: /// /// Compares two values and returns the comparision result. diff --git a/Source/Engine/AI/BehaviorTree.cs b/Source/Engine/AI/BehaviorTree.cs index b7925aee0..aebc07343 100644 --- a/Source/Engine/AI/BehaviorTree.cs +++ b/Source/Engine/AI/BehaviorTree.cs @@ -11,6 +11,18 @@ using FlaxEngine.GUI; namespace FlaxEngine { + partial class Behavior + { + /// + /// Gets the blackboard of the given type. + /// + /// The blackboard type. + public T GetBlackboard() + { + return Knowledge.GetBlackboard(); + } + } + partial class BehaviorKnowledge { /// @@ -33,6 +45,16 @@ namespace FlaxEngine { RemoveGoal(typeof(T)); } + + /// + /// Gets the blackboard of the given type. + /// + /// The blackboard type. + [Unmanaged] + public T GetBlackboard() + { + return (T)Blackboard; + } } partial class BehaviorTreeRootNode