Forum Discussion
molton
12 years agoExplorer
Threading with Unity problems
Hello, as far as I can tell, threading is pretty useless/impossible to use with Unity. It seems like everything but the most basic lines of code can't be run from a thread. Unity says "(whatever) has to be run from the main thread" Is there a way around this restriction because it really sucks. The only things I'm able to put in a seperate thread don't help me improve performance. I just keep thinking if Unity is a popular modern game engine, surely there must be a way to impliment threading in a useful way. Anybody have any luck improving their FPS with threading in Unity? Will Unity 5 support putting more Unity functions in a thread? I see one of the new features is "New multithreaded job scheduler" is there an old one? Thanks.
2 Replies
Replies have been turned off for this discussion
- PlanetTimmyHonored GuestYou can't access the hierarchy in a thread. However that doesn't mean that you can't use threads; you just have to put in a bit of extra work, and it often means caching a copy of some of the data.
For instance, if you wanted to do crowd AI in a thread, you'd probably want to store the related data in your own (non-monobehaviour) structures. At the start of the frame, kick off a thread that updates the structures, but does not access anything in the hierarchy. On LateUpdate somewhere, have something that waits for the thread to finish and then updates all the appropriate Unity objects using the stored data structures. - moltonExplorerOk, thanks. I'll keep that in mind but it won't help me with my current problem I think. I'm trying to only enable the colliders of objects near the player controller because having them all enabled all the time kills performance in several ways in my scene. I'm currently using a coroutine that works pretty well but usually comes with a 20-30 FPS drop. I don't think there's anyway to externalize the collider data like you mentioned but if there was that would work. I'll probably try to slow down that coroutine and see if that works.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 7 months ago
- 7 months ago
- 2 years ago
- 6 months ago
- 3 months ago