0
0
Unityframework~8 mins

Component communication in Unity - Performance & Optimization

Choose your learning style9 modes available
Performance: Component communication
MEDIUM IMPACT
This affects frame rate and responsiveness by how often and how many messages or events are sent between components during gameplay.
Sending messages between components every frame
Unity
void Update() {
    if (shouldAct) {
        otherComponent.DoActionDirectly();
    }
}
Direct method calls avoid reflection and reduce overhead.
📈 Performance GainReduces CPU usage and improves frame rate stability
Sending messages between components every frame
Unity
void Update() {
    otherComponent.SendMessage("DoAction");
}
SendMessage uses reflection and is slow; calling it every frame causes many costly lookups.
📉 Performance CostTriggers multiple script lookups and slows frame rate under load
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
SendMessage every frameN/AN/AN/A[X] Bad
Direct method calls on conditionN/AN/AN/A[OK] Good
Events invoked every frameN/AN/AN/A[!] OK
Events invoked on state changeN/AN/AN/A[OK] Good
Rendering Pipeline
Component communication affects the scripting phase of the frame where game logic runs. Excessive messaging increases CPU work before rendering.
Scripting
CPU Processing
⚠️ BottleneckScripting phase due to reflection or excessive method calls
Core Web Vital Affected
INP
This affects frame rate and responsiveness by how often and how many messages or events are sent between components during gameplay.
Optimization Tips
1Avoid SendMessage calls every frame; use direct calls instead.
2Invoke events only when necessary, not continuously.
3Minimize reflection and frequent messaging to keep scripting time low.
Performance Quiz - 3 Questions
Test your performance knowledge
Which method of component communication is best for performance in Unity?
ADirect method calls only when needed
BSendMessage every frame
CInvoke events every frame
DUse reflection-based messaging every frame
DevTools: Profiler
How to check: Open Unity Profiler, record gameplay, look at CPU usage and scripting time, check for spikes during messaging calls.
What to look for: High scripting time or garbage collection spikes indicate inefficient component communication.