- Home /
workaround for parallelizing function calls from Unity API?
Hi there,
I am doing a visual recognition system, and to do more advanced stuff I need to use a lot of raycasts, however that won't do it in term of performance if they have to be done sequentially. On the other hand, it looks like it is not possible to parallelize function calls from the Unity API, is it really completely the case or can I do some kind of configuration to allow that?
Thank you in advance for your help,
Minsc
Answer by Dave-Carlile · Jun 29, 2015 at 09:15 PM
If you need actual parallelism you can use threading, but all access to the Unity API must happen on the main thread.
Another common technique for heavy workloads is to spread the work across multiple frames - Coroutines are good for doing this. If you're not doing a lot of raycasts all the time this may be a viable option.
Cool thanks so it is actually possible to parallelize Unity API functions, I will look into the threading option I need to do a lot of raycasts, it is for a pointcloud detection.
I may not have been clear - Unity API functions $$anonymous$$UST be executed on the main thread, meaning you can't execute them in your own threads.
Yeah, if you wanted to multithread it, you'd have to implement everything yourself.
Um okay indeed, I will look into alternatives or maybe implement my own raycast system. But it is only Unity API that is not parallelizable right? If I use another API in my code can I still multithread it?
Yep - if you want to do your image recognition stuff in a separate thread, that's fine, but the initial raycast(s) must be from the main thread.
Your answer
Follow this Question
Related Questions
[SOLVED] How to set an object's rotation parallel to a wall. 1 Answer
How to raycast on multi core ECS 0 Answers
raycast help need 2 Answers
Push object in direction of camera 0 Answers