Good questions.
- Virtual calls are always expensive than direct calls. And you should avoid having too much Update calls. It's better to have a manager class with one Update and call other classes' fake update methods than having separate Update methods. [Here is detailed information.][1]
- It really depends on your usage and your platform. Extensive use of them will certainly bite, but you should experiment with it.
- It is a bit costlier than calling components, but you definitely can use it. It is funny that in earlier versions, the question was "can or can't" rather than "ok or not". [Detailed information is here.][2]
- There are definitely better alternatives. Check these: [More Effective Coroutines][3] | [UniRx][4]. Additionally, Coroutines only work in main thread. If you are looking for a way to use multithreading, these links may help : [Threads forum discussion][5] |
[Coroutines vs. Threading][6].
- I've seen some people use events extensively, if you know your way, it will not be a callback hell. But If you ask my opinion, Don't rely on one system. It is okay to use systems as long as they work in harmony and easily understandable. Use things that make your life easier, don't use things that will make your life harder just because "you need to stick with it". Perhaps [this link][7] will look familiar since you are a software engineer and can help you decide which way to go on.
- I need an example on how you are planning to use it. If you are thinking about anonymous and named methods, there is merely a performance difference.
Agreed with caching. I also see a lot of this:
void Update()
{
transform.position = new Vector3(5,0,0);
}
Instead of this:
Transform myTransform;
void Start()
{
myTransform = transform;
}
void Update()
{
myTransform.position = new Vector3(5,0,0);
}
If you use transform or gameObject in Update, it is drastically better caching reference of it. In one of my project when I was a beginner in unity, referencing myTransform boosted 10 fps performance.
Hope they can help you to make your mind a bit clearer.
[1]: https://blogs.unity3d.com/2015/12/23/1k-update-calls/
[2]: https://forum.unity3d.com/threads/getcomponents-possible-to-use-with-c-interfaces.60596/#post-2751059
[3]: http://trinary.tech/category/mec/
[4]: https://github.com/neuecc/UniRx
[5]: https://forum.unity3d.com/threads/threads-example.135578/
[6]: http://answers.unity3d.com/questions/357033/unity3d-and-c-coroutines-vs-threading.html
[7]: http://answers.unity3d.com/questions/1354956/what-are-the-best-practices-of-designing-code-arch.html
↧