x


Can an object script NOT contain Update()?

If I have a GameObject with three scripts attached to it, do all three scripts have to have an Update() function? Can 1, 2 or even all 3 have no Update() at all but just normal called functions, maybe that are called by another script attached to another GameObject?

And if so, does it make any difference? I read somewhere on another forum that for iPhone optimisation, it's better to have one function to affect a whole collection of objects, rather than each of those objects having its own little Update()...

more ▼

asked Feb 03 '11 at 09:44 PM

robinking gravatar image

robinking
756 61 68 81

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

No, none of the scripts on your GameObject have to include an Update() function.

The memory cost for ten Update()'s is really affected by what you do in it. Alone, it's minimal, so I wouldn't worry about it.

more ▼

answered Feb 03 '11 at 09:49 PM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

I see. Does an empty Update() function actually cost some performance? Over and above a script with lots of called functions but no Update() function? (if I had thousands of instances, for example)

Feb 03 '11 at 10:25 PM robinking

An empty Update() function costs next to nothing, because you're not doing anything to use up memory in it. Even if you did have thousands of instances, the memory use is still tiny and not worth worrying about. ;)

Feb 03 '11 at 10:28 PM e.bonneville

That's not really true; an Update call does have overhead, and should be removed if you're not using it. Thousands of objects with empty Update functions will have a noticeable performance hit an an iPhone (not that you'd want thousands of objects on an iPhone to begin with).

Feb 03 '11 at 11:06 PM Eric5h5

Cool, thanks for the info!

Feb 04 '11 at 12:12 AM robinking

Thanks for clearing that up, Eric. I've not worked with iPhone before, so my experience is solely with high-end platforms. As a result, I don't know a whole lot about iPhone optimization.

Feb 04 '11 at 12:33 AM e.bonneville
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1998
x492
x470

asked: Feb 03 '11 at 09:44 PM

Seen: 797 times

Last Updated: Feb 03 '11 at 09:44 PM