- Home /
Messenger.Broadcast VS GetComponent
what is better for higher frame rate Messenger.Broadcast or GetComponent?
Answer by aldonaletto · Jan 16, 2012 at 12:00 AM
Do you mean BroadcastMessage? GetComponent is faster and more versatile: you can call any function, or access any variables in the target script. On the other hand, the target script must be known at compile time, what can be a problem if it was written in a different language.
BroadcastMessage takes more time, you can pass only a single argument and receive no return values, but it's the better option when you must call the same function in different scripts. Good examples are the function "Fire", that can be called in the current weapon even if each type uses a different control script, and "ApplyDamage", which also may exist in an enemy object, or a wall, or a tank, or the player etc.
Your answer
Follow this Question
Related Questions
Bad fps on blank project android,Very bad fps on completely blank project (mobile) 0 Answers
Are .transform .gameObject .rigidbody component calls or just pointers? 3 Answers
does using get component slow down game a lot? 1 Answer
[SerializeField] for self components instead of GetComponent<>? 1 Answer
Framerate drops when I preview my game, what is particleSystem.renderSingle in profiler? 0 Answers