informa
2 min read
Featured Blog

Counterintuitive

In which I complain about children and components.

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...

"In truth I haven't played much since the baby came in June but give me half a minute an' I'll get this fiddle back in tune"

Latest Jobs

Treyarch

Playa Vista, California
6.20.22
Audio Engineer

Digital Extremes

London, Ontario, Canada
6.20.22
Communications Director

High Moon Studios

Carlsbad, California
6.20.22
Senior Producer

Build a Rocket Boy Games

Edinburgh, Scotland
6.20.22
Lead UI Programmer
More Jobs   

CONNECT WITH US

Register for a
Subscribe to
Follow us

Game Developer Account

Game Developer Newsletter

@gamedevdotcom

Register for a

Game Developer Account

Gain full access to resources (events, white paper, webinars, reports, etc)
Single sign-on to all Informa products

Register
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more