Menu

How slow is Unity's SendMessage? Benchmarking it against interfaces, UnityEvent and C# events with 10,000 enemies
📰

How slow is Unity's SendMessage? Benchmarking it against interfaces, UnityEvent and C# events with 10,000 enemies

DEV Community: csharp·Masaki Mori·about 18 hours ago
#uatnWlXT
#devtocsharp#devto#dev#sendmessage#takedamage
Long article (1410 words) — no AI summary yet.
Reading 0:00
15s threshold

When I ask an AI assistant to write damage handling for a bullet in Unity, it sometimes produces this:

void OnTriggerEnter ( Collider other ) { other . SendMessage ( "TakeDamage" , 10 ) ; }

Enter fullscreen mode

Exit fullscreen mode

It's convenient: you can call a method by name without knowing the target's type. But SendMessage looks the method up by its string name and boxes the argument as an object before calling it. I measured how much that actually costs compared with the alternatives.

The six approaches

I placed 10,000 enemies in a scene. Every frame, an attacker tells each enemy "take 10 damage" once.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.