Broadcast vs Events and CoRoutine vs async Task?

Hey there,
just completed the realm rush section, and now at the end, there are two questions left in my head.

Broadcast with a method name as string sounds like a reflection invoke on a group of objects behind the scenes. this is extremely inefficient. Is there a reason why not using the c# event system or handle method pointers by ourselves? If you know how to add/remoive event handlers correctly, this should be way more efficient.
Do I miss something here?

Coroutines are not really an async thing, right? they are still in the mainthread, just skipped for x frames until the sum of delta time reaches the threshold of the wait time we yielded. Is there a reason not using the Task library?

I believe BroadcastMessage is more expensive than events, yes. But with this being a very small game and a beginner course, most students don’t know how to add/remove event handlers correctly and this is a simpler way of achieving the same result.

async does not mean different thread. You can have a whole application littered with asynchronous tasks that never create another thread. From the Microsoft documentation:

The only difference between a coroutine and async/await is how it works. See this article Async in Unity (better or worse than coroutines?) - Game Dev Beginner
Again, considering that this is a beginner course, I believe coroutines are far easier to wrap your head around.

1 Like

Thanks for your kind reply!
Yes I am aware that this is a beginner course, but I am just a beginner in terms of unity, not in C#, and I wanted to get some understanding about the differences.
I know, that it requires a Task to deliver workload to a background thread, I could even create my own sleeper or queue thread as a new Thread – again, I just wanted to increase my understanding of the things behind the scenes.

Your explanation confirmed my thoughts on this! Again, thank you very much!

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms