Global Collision

I have a color matching game for the iPhone where I am pinching objects together. One problem I have is that as much objects appear on screen, the frame rate slows down. The models themselves are pretty small and each one only has one texture. Each object does have a small script attached to it to respond to onCollision events. As I understand it, the more scripts in a scene, the longer a frame takes to render. I would like to have one script that looks at all the collisions in a frame so that I don’t need a script on each object. Is that possible?

That’s not possible, no, but the real issue is not scripts so much as the number of separate objects being rendered, and hence an excessive number of draw calls. There have been several topics here covering various ways to combine multiple moving objects into one, if you want to take a look.

–Eric

I was just seeing if there was a way to avoid having a script on each object.

Actually, your response reminds me that I should profile before I attempt to optimize. Each object having its own script may not be a problem at all.

Thanks.

Not if you need OnCollision functions, no.

I guarantee 100% that the problem is caused by having too many draw calls. :slight_smile: Having many scripts will have an impact, but not nearly as much as having many draw calls.

–Eric

Agreed. I am trying to use real time lighting as well. The objects just don’t look that great without real time lighting.

Having an abundance of scripts is not bad by itself, its having a large number of scripts with function Update(). ReJ provided some information on this in a thread I read a while back…

http://forum.unity3d.com/viewtopic.php?t=17834&highlight=

Actually I tested it, and having a lot objects with a script, even if it’s just an empty OnCollisionEnter function, will be slower than having a lot of objects, but with only one of them having the script. Granted it’s only by a small amount, and wouldn’t even be noticeable in normal circumstances on a desktop (unless you had thousands of script instances, probably).

–Eric