ricardojmendez / UnitySteer

Steering, obstacle avoidance and path following behaviors for the Unity Game Engine
https://numergent.com/tags/unitysteer/
Other
1.2k stars 275 forks source link

Threaded Ticked Queue #37

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi,

I am wondering: would run the queue in a dedicated thread make sense? It doesn't directly apply modifications to transforms or GameObject, right? I'd like to run a lot of AutonomousVehicle on mobile, several hundreds at least. so I am wondering on possible ways to make it happen. I noticed with a couple of hundreds just the queue update will take something between 25-40ms to run on my Android device. Plus the rest, I am far from 30fps.

Cheers.

ricardojmendez commented 8 years ago

The unity guideline is that the API is not thread safe, as a whole. They don't just circumscribe it to modifying game object properties. While at first blush it'd seem reasonable to expect that as long as you're not attempting to update objects you should be fine with querying, it gets iffier when we're talking about (for instance) querying for nearby colliders. We could be querying, caching and making calculations based on an object which is on the process of being released or destroyed, just because we're doing it out of the game loop.

If you need to run a lot of vehicles on limited hardware, chances are you need to look very closely at which steering behaviors you're applying, which ones are consuming the most time, and if there's a way to optimize/simplify the approach. The profiler is your friend there.

Hope that helps.