First of, does StartCoroutine() create a new thread? If not just tell me that and ignore the rest of this post.
If it does, what if I have a server, with 500 player objects instantiated. Each of those player objects has a script attached with a coroutine running inside. Does that mean i’ll have 500 threads?
Sorry if it’s a dumb question, I’m just wondering should I organize my scripts differently if this is the case.
No, new threads only are created if you ask mono to do so through the .NET threading stuff
Note that the unity API is not thread-safe. Co-routines work by “manually” yielding the process from your co-routine back to the rest of the application. All coroutines are updated after LateUpdate is called.
Cool, thanks
I got another question. Would it be more effective to have everything(like position, animation, etc) connected to one single NetworkView, or to have one NV for each of those (position, animation, …)?
I have a very low sendrate(5), and currently I have separate network views for position, animation and player hitpoints.
But if I have only one network view, all of this data will be sent in one packet. (I realize it would probably be sent more often because there’s a larger chance that some of these properties will change)
But this would be more effective. Right?
(I’m asking because the network examples use separate network views)
I’d keep them separated as, like you mention, you would have that network view update a lot more often - transmitting information which isn’t relevant to the reason for the update.
The reason I’m asking is because TCP has like 40 bytes overhead, and UDP has 30. I’m not sure anymore which one Unity uses.
It would probably be more effective to send one 500 byte packet + 30 bytes overhead(530b total) than
sending 10 x 50 bytes with 10 x 30 bytes overhead(800b total).
Gets even worse when you’re sending just 1 byte for animation updates.
It would be cool if unity internally grouped network views data and sent them as a single packet…(Does it?)
@AngryAnt If I DO group position, animation, etc in one network view, and only animation changes, will only the animation be sent, or will the position be sent also? (Using Delta Compression)
Everything tied to a network view will be sent when the network view detects a need to update.