Messaging Confusion

Hi, all!

So throughout my game project whenever I want to do damage to an object I have been having the object that gets hit call the function do damage itself on itself. For instance, when an enemy fires, it takes its ‘damage’ variable and plugs it into the bullet. The player gets the ‘damage’ variable from the bullet and applies it to itself.

Well, what if I wanted to damage everything onscreen?

One way would be to run a for loop through all of the children of my ‘enemy’ empty parent object,

But what about using the messaging system?

I have seen others use it, but have never found any practical use of it for myself. When I was programming games with Blender, I used messaging all of the time, but that was simply because it allowed me to not code much (a messaging system was supported in their ‘GameLogic’ UI ).

Currently, in my project, I have a BUNCH of ‘cahching this object’s script in the start’ and ‘using that variable when I need to’. Code can get really cluttered, as some gameObject have to be cached all of the time if I need to access them. I understand that this is not necessary with Messaging.


  • When should I be using the messaging system?
  • How should I use it? (this can be simple)
  • When should I avoid using it and opt for other methods for calling functions on GameObjects?

Thanks! - YA


Using SendMessage() system is heavy. It’s not efficient at all.

You can try to use a saved list somewhere, like a game manager.
In Start(), you register your unit in the game manager.
In OnDestroy(), you unregister your unit from the game manager.
If you have to while on every unit, you can simple use the list in the game manager.
This is more efficient than SendMessage(), FindObject, GetComponent(). Because don’t have to search, it’s already ready!

You can take a look at this link: