- Home /
How does SendMessage work in the background?
It looks like every time a message is sent it iterates through all the components looking for the function. Is that true or does it do some clever optimization in the background, As in maintaining a look up table of some sort?
Answer by jonas-echterhoff · Jan 12, 2010 at 11:33 AM
Send Message will indeed use reflection internally. So, it is by no means as fast as some custom solution using delegate tables. If you use this a lot, replacing it makes a lot of sense.
Answer by Brian-Kehrer · Dec 24, 2009 at 12:26 AM
I believe it internally uses some sort of delegate system - however, despite whatever optimizations it may or may not use, it is slow (relatively).
If you are interested for optimization purposes, the answer is that using SendMessage every frame (such as in Update) is not a good idea on things like the iPhone.
thanks for the input, what i had in $$anonymous$$d as a alternative is my own message system. Basically each component would have a look up table where other components would subscribe to events they are interested in.
If Unity by default is working like that then i dont see any advantage using my system. $$anonymous$$ay be i will ask the Unity Team...
Answer by Neodrop · Dec 24, 2009 at 03:00 PM
I thing messages is based on "Invoke" method/ Not so fast as delegats.
Your answer
![](https://koobas.hobune.stream/wayback/20220613185551im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
SendMessage script problem 2 Answers
NotificationCenter Help Needed 0 Answers
Error on my javascript code 1 Answer
SendMessage has no Receiver 1 Answer