- Home /
Difference between Unity's messaging system and other custom messaging systems?
I recently started looking into using messaging systems, which are new to me, and part of my learning process to better myself at c# programing and writing better, more efficient code.
I have been reading about and using Unity's own "SendMessage" system, but I recently came across some video tutorials in which the user is using a custom messaging system like this one, and I was wondering a few things:
- Why is he not using Unity's built-in messaging system?
- What's the difference between the 2?
- Does Unity's messaging system have any major pros or cons?
Like I mentioned above, messaging systems are new to me, and although I understand their purpose and usage, I do not know how to tell a good one from a bad one, or whether or not Unity's built in messaging system will do everything I need it to do.
Answer by Jake-L · Feb 24, 2011 at 07:33 AM
The difference is in the way how messages got from the sender to the consumer/receiver. The buildin system uses reflection to call a function you provide. Reflection is somewhat slow, so if you use this extensively (every frame) this may slow down your game. Another difference (some may say drawback) is that you need to know the consumer to send him the message directly.
Other systems like that you linked rely on delegates and events (ask your favorite C# learning book or google it if you want more details). Basically this works like a mailing list subscription: an object that want to receive certain types of messages subscribes itself on a list. When the event fires, all subscribers on the list got this message. The big advantage is that you fire events no matter to whom and every object that want it will get it.
Both systems can be useful, it depends on the type of application and how you layout your code.
Hope that helps...
Jake
Jake L, thanks a lot for the explanation, it does help a lot. I do like the CSharp$$anonymous$$essenger messaging system better, as it seems to give the user more control, and from what I have read so far, would be a faster solution for mobile development. Thanks again for your help!
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
BroadcastMessage between children? 3 Answers
iPad touch scripting... 0 Answers