- Home /
I want to know more about how Unity works, but how?
I'm sure I'm not the first person to ask this question, but I couldn't find any good topic about it, so I'm asking here.
I've been using Unity for a few weeks now and am loving it as it makes doing a lot of things very simple. However, there are a few things where I'll try to do something and Unity doesn't exactly behave as expected, or I end up doubting the efficiency of my implementation because I don't know what the Unity API functions are really doing when I call them.
For example, right now I'm making a small tower defence game as a learning exercise and want to get a list of n monsters within range x of a tower ordered by distance. This kind of thing seems like something that might be built into Unity, but I couldn't find anything quite that specific. However, there ARE functions that let us get a list of objects by type, or get objects within a sphere around a point. Doing this is easy and I have no problem writing my own code to then sort the list of objects as I need. However, I don't know how efficient that is because I don't know how Unity is getting the objects in the scene.
I don't need to know the really low level stuff, but it would be nice to know if Unity already performs spatial partitioning on objects in the scene to speed up finding objects within a range etc. or if I need to actually partition the scene and manage lists of objects myself. This is the kind of annoying code that I would rather not be writing so it would be great to know if it's something that's not necessary.
Another example is collision detection. Unity probably has very optimised collision detection routines in native code, but if I wanted to make a 2d bullet hell shooter and all my collisions are 2d points and boxes or circles, am I better off just doing it myself and taking the speed penalty of it being in a script? I'm asking because I think even the box collider is OBB, not AABB, so perhaps there is some large performance penalty there that I don't know about.
A friend and I also had a bit of trouble using the Networking in Unity, which might have been a little easier if we knew more about how it was working and what Unity was sending.
Sorry for the long post. If there is any good resource for finding out a little more about the internal workings of Unity, it would be fantastic and enlightening to have a look at it.
I think this would get better answers/discussion in forum.
You're probably right, but I can't seem to make a forum account at the moment. I didn't have one before Unity started the UDN, so I can't claim any account, but I don't want to lose this account. It seems to be impossible to create a forum account under an existing Answers only UDN account :(
Anyway, if anyone has any answers/opinions it would still be good to hear.
Answer by Kryptos · Jul 03, 2012 at 01:43 PM
You can take a look at Unity's DLL such as UnityEngine.dll. Open them with monodevelop (using the Library explorer) to see the CIL or an approximate of the corresponding C# code.
This helps me sometimes. For example you can see that GetComponent() is as efficient as GetComponents() because the first ones calls the second one and returns the first occurence.
Of course, most part of the DLL is only a wrapper around native call to the internal engine. So you may not go very deep.
Answer by Baldinoboy · Jul 03, 2012 at 01:58 PM
Your way ahead of me in skill. So this answer might be stupid to you but you can learn everything that Unity has implemented in it in the Reference Manual on the Unity site. Read through that, which you might already have, and you'll learn everything Unity has to offer.
Your answer
Follow this Question
Related Questions
(2 hidden skinned meshes) or (1 extra draw call) for character props? 2 Answers
Simple Animation showing as ~6.3 in Xcode console profiler 0 Answers
Is there a performance difference between Unity's Javascript and C#? 6 Answers
Are .gameObject and .transform both using GetComponent() in the background? 1 Answer
Add 2d rigidbodies to moving objects to increase performance or not? 1 Answer