diff --git a/src/features/editScene/EditorApp.cpp b/src/features/editScene/EditorApp.cpp index 6e1a0de..96b34b2 100644 --- a/src/features/editScene/EditorApp.cpp +++ b/src/features/editScene/EditorApp.cpp @@ -330,6 +330,8 @@ void EditorApp::setup() // Wire up AnimationTreeSystem for animation state machine control m_smartObjectSystem->setAnimationTreeSystem( m_animationTreeSystem.get()); + // Wire up EditorApp for game mode detection + m_smartObjectSystem->setEditorApp(this); // Setup CellGrid system m_cellGridSystem = diff --git a/src/features/editScene/systems/SmartObjectSystem.cpp b/src/features/editScene/systems/SmartObjectSystem.cpp index ecdf2b1..43e5582 100644 --- a/src/features/editScene/systems/SmartObjectSystem.cpp +++ b/src/features/editScene/systems/SmartObjectSystem.cpp @@ -8,12 +8,16 @@ #include "../components/ActionDebug.hpp" #include "../components/NavMesh.hpp" #include "../components/AnimationTree.hpp" +#include "../components/PlayerController.hpp" +#include "../components/EntityName.hpp" +#include "../EditorApp.hpp" #include "NavMeshSystem.hpp" #include "BehaviorTreeSystem.hpp" #include "AnimationTreeSystem.hpp" #include #include #include +#include SmartObjectSystem *SmartObjectSystem::s_instance = nullptr; @@ -188,6 +192,36 @@ void SmartObjectSystem::update(float deltaTime) db = &database; }); + // Determine if we're in game mode. In game mode, player-controlled + // characters are managed by PlayerControllerSystem and should NOT + // be processed by SmartObjectSystem to avoid animation conflicts. + // In editor mode, player characters can still be tested via ActionDebug. + bool isGameMode = false; + if (m_editorApp && + m_editorApp->getGameMode() == EditorApp::GameMode::Game && + m_editorApp->getGamePlayState() == + EditorApp::GamePlayState::Playing) { + isGameMode = true; + } + + // Build a set of entity IDs that are player-controlled characters. + std::unordered_set playerCharacterIds; + if (isGameMode) { + m_world.query().each( + [&](flecs::entity, PlayerControllerComponent &pc) { + if (pc.targetCharacterName.empty()) + return; + m_world.query().each( + [&](flecs::entity e, + EntityNameComponent &en) { + if (en.name == + pc.targetCharacterName) + playerCharacterIds + .insert(e.id()); + }); + }); + } + // Process each character with a blackboard (AI-driven characters) m_world.query() .each([&](flecs::entity e, CharacterComponent &cc, @@ -196,6 +230,12 @@ void SmartObjectSystem::update(float deltaTime) (void)trans; (void)bb; + // Skip player-controlled characters - they are managed + // by PlayerControllerSystem, not by SmartObjectSystem AI. + if (playerCharacterIds.find(e.id()) != + playerCharacterIds.end()) + return; + auto &state = m_states[e.id()]; state.scanTimer += deltaTime; @@ -597,6 +637,12 @@ void SmartObjectSystem::update(float deltaTime) (void)trans; (void)debug; + // Skip player-controlled characters - they are managed + // by PlayerControllerSystem, not by SmartObjectSystem AI. + if (playerCharacterIds.find(e.id()) != + playerCharacterIds.end()) + return; + auto &state = m_states[e.id()]; // When the behavior tree is running (via ActionDebug), diff --git a/src/features/editScene/systems/SmartObjectSystem.hpp b/src/features/editScene/systems/SmartObjectSystem.hpp index c04f514..3be9be4 100644 --- a/src/features/editScene/systems/SmartObjectSystem.hpp +++ b/src/features/editScene/systems/SmartObjectSystem.hpp @@ -10,6 +10,7 @@ class NavMeshSystem; class BehaviorTreeSystem; class AnimationTreeSystem; +class EditorApp; /** * System that manages Smart Object interactions. @@ -42,6 +43,18 @@ public: m_animTreeSystem = system; } + /** + * Set the EditorApp for game mode detection. + * When in game mode, player-controlled characters are skipped + * to avoid animation conflicts with PlayerControllerSystem. + * In editor mode, player characters can still be tested via + * ActionDebug. + */ + void setEditorApp(EditorApp *app) + { + m_editorApp = app; + } + void update(float deltaTime); /** @@ -100,6 +113,7 @@ private: NavMeshSystem *m_navSystem; BehaviorTreeSystem *m_btSystem; AnimationTreeSystem *m_animTreeSystem; + EditorApp *m_editorApp = nullptr; std::unordered_map m_states;