Counterintuitive

(reposted from Gamasutra; so context might be a bit off as we were in the middle of a little war over here).

In between a war and a hard place life goes on and code is written. But since I’m not in the happiest mood to write something constructive I’ll complain. And what shall I complain about, oh great and noble sir or madam? What a silly question… Unity of course.

Let us imagine a game object. An entity if you please. And let us call it, um, I don’t know, “Amir”. Let us delve deeper into the mysteries of creation and attach three other entities to “Amir” (parenting if you will). We shall dub these, “Rob”, “Bob” and, eh, “Slob”. Why not?

To each of these strange and wonderful objects we’ll endeavour to attach a single component called “Health”. Now, four entities, four components. Let me paint you a picture. A simple one, of hard lines and boxes. Of the UML persuasion.

uml

Pop quiz, hotshot.

Amir.GetComponentsInChildren<Health>()

How many components have we got?

My wife’s (who is both amazing and wonderful) first reaction was:

“Are you really going to teach me programming at ten at night?”

I proceeded to get a notepad and she sighed, resigned. Her second reaction, after a quick sketch.

“Three”

And if that wasn’t your first reaction you should probably think long and hard about life in general… Of course if that was your first reaction you probably haven’t been working with Unity for very long either.

“Ah ha!” I exclaimed loudly, “You would think so!”. Then hung my head, “But the answer is four”.

I’ll end this post with a quote from the Unity’s documentation page.
Returns all components of Type [type] in the GameObject or any of its children.

Why? F*** if I knew…

Hey mister if you want to walk on water, would you drop a line my way
Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s