# Any recommendations for switching between State Machines / Behavior Trees when an NPC has disjoint roles? — retained record

> Retained reddit record from reddit:gamedev.

Canonical: https://highsignal.app/data/records/73dd4318a46bd6d0

[← sources](https://highsignal.app/data)


source: [reddit](https://highsignal.app/data/reddit) (reddit:gamedev)  published 2026-10-13 14:49 ingested 2026-10-14 02:38

[original source ↗](https://www.reddit.com/r/gamedev/comments/1x4yoer/any_recommendations_for_switching_between_state/)

## retained text



```
Let's say we have an NPC AI that has two disjoint roles, Roles A and B, and the NPC can switch between them

For example, an NPC working in a restaurant can switch between being a cook and being a janitor. There are no shared duties at all. The roles are disjoint

Since the roles are disjoint, Role B is not simply a sub-role of Role A (vice-versa), rather an entirely different logic flow

There are also NPCs that solely have Role A and solely have Role B. So the roles A and B are driven by their own state machines / behavior trees

So if I have an NPC that can do both roles, should I simply put two state machines / behavior trees (one for A, one for B) on the NPC, and just toggle between them?

The state machine / behavior tree that is active on the NPC will have it's own Update() method. So whichever is active, it's Update method will run

So to implement such a behavior, where an NPC can switch between disjoint roles, is the solution simply: for each role an NPC can take, attach the state machine / behavior tree onto the NPC, and toggle between them

The one concern I have is that there may be a small judder when toggling between the state machines / behavior trees. I'll figure that out, however I wanted to know if there is a more standard solution

Thanks
```



document fetched 2026-10-14 00:26 · canonical https://reddit.com/r/gamedev/comments/1x4yoer/any_recommendations_for_switching_between_state
