- Home /
Best approach for complex AI preformance
I'm working on a relatively complex AI that uses a game theory (weighted node) approach to decision making. I have the basic functionality working, but I am already noticing significant 'hiccups' whenever large calculations are performed.
For example, an AI might need to simulate all possible combinations of moving to and interacting with N objects. Doing this in the main thread greatly hurts performance. I thought I could somewhat easily dump the AI simulation logic into background threads, but I'm struggling with errors from the Unity Engine not being able to access components from outside the main thread.
Before I poke around any more, I want to back up and see if there is a better overall approach for this kind of thing.
Should I try to detach my AI logic entirely from Unity dependent objects? This would be quite tough since some of the plugins I'm using have built in Unity requirements.
Any kind of advice or thoughts would be appreciated. I'm a little lost on what to do at this point.
Answer by georgeq · Jun 08, 2015 at 10:58 PM
I don't know the Unity internals, but I trust there must be a very good reason to prevent us from using threads. Since no threads are available, the closest alternative at hand are Coroutines, you may not reach the level of performace you would get by using threads, but if you do a good job issuing a yield return null at the right moments, you may get a decent performance.
Your answer
![](https://koobas.hobune.stream/wayback/20220613200721im_/https://answers.unity.com/themes/thub/images/avi.jpg)