Which is a better habit for programming?

I never made a big game so I never worried about preformance. Now I’m starting a big one so I want to know if I have a good habit here. I make really small scripts, and use “send message” a lot in my code. However does “send message” have a impact on preformance? Should I make bigger scripts and use send message less? Thanks!

Script size and message passing aren’t necessarily related. Creating monolithic scripts to save on message passing is definitely a bad idea. Are you aware that there are methods other than SendMessage for scripts to communicate?

It really depends on what you call “a lot”, though. If you’re talking about thousands of calls per frame I’d look for a more efficient method. If you’re talking about a bunch of calls when specific events occur, it’s probably not an issue.

From what i have read, send message can be about 100x slower than just directly accessing another objects function.
Not sure about this though, never used it myself.
Also, script size have no direct relation with script speed, but small scripts are easier to manage.

For a big project, stop using send message. Start caching components you need to call a lot.

There was another thread on using SendMessage not long ago:

http://forum.unity3d.com/threads/131693-SendMessage-vs-direct-function-calls

As a game developer coming from a C/C++ background on limited systems, I’m always thinking about speed. I may not be using Unity’s advanced features as expected, but sometimes they are not the right choice for speed reasons.

If I need objects to communicate with each other I set up reference pointers in each object when they are created ( start() ), caching them like already mentioned and I then call public functions directly to have objects talk to each other.

It’s a great idea to have correct OO programming, and keep objects completely separated, but in reality when making a game it’s sometimes beneficial to break conventions for speed reasons. Keep some sense of organization though otherwise you end up with too many hacks and strange bugs can crop up everywhere.

Just my opinion as a hobby game programmer. It might be sub-optimal, but it works for me. :slight_smile: