It seems like a long shot, but can StateTrees be used outside of the game thread? I have an enormous number of AI enemies, most of whom are already not actors but primitive meshes, and I’d like to manage at least their core behavior in a threaded manner. Can I use StateTree for this? Or BehaviorTrees? If not, what particulars of their construction re: data read/write are going to be most prohibitive? If so, is there a guide, library, or plugin I could use? I’m quite comfortable with C++, or as comfortable as a sane person can be.
Hello,
StateTrees are generally designed to run within the game thread because they often need to interact with game objects and the game world, which are not thread-safe. This means that using them outside the game thread can lead to issues with data consistency and race conditions. However, there are some strategies you can consider:
Data Management: Ensure that any data accessed by the StateTree is thread-safe. This might involve using locks or other synchronization mechanisms, but this can introduce performance overhead.
Task Offloading: You can offload certain tasks to worker threads and then synchronize the results back to the main thread. This way, the my ford benefits StateTree itself remains in the game thread, but heavy computations are done elsewhere. This is a C++ library for building Behavior Trees, which includes tutorials and examples on how to create and manage Behavior Trees.
Hope that helps.
Other responses are incorrect, state trees can in every meaningful way be used off thread. it’s not trivial, but it can be done. In fact, if you take a look inside Mass, you’ll find that it’s got a threaded executor. I know you’re probably just a scammer, but this might be the only damnable result and I’m not leaving it like this.
Threading state trees is risky and errorprone, but can be done.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.