public void TESTMoveOtherRows()
{
Debug.Log("Testing!");
}
But when I run I get:
SendMessage TESTMoveOtherRows has no receiver!
UnityEngine.Component:SendMessage(String)
RowController:smile:ieFunction() (at Assets/Scripts/RowController.cs:50)
c__Iterator1:MoveNext() (at Assets/Scripts/RowController.cs:66)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
What am I doing wrong so it isn’t receiving the message?
Sorry for the noob question, it’s the first time I’m using SendMessage.
Yup, that’s exactly what I had to do. Also a bug in my brain made me call RowController when I needed AllRowController, which made me think there was a problem with SendMessage.
Yeah I don’t really see a reason to use SendMessage, I just wanted to try it out but so far it seems pointless.
If you know the exact type of component you want to talk to and can make the method public, that’s clearly better than SendMessage. But if you’re making a system that you want to work with multiple decoupled types, SendMessage can be helpful. For example, in a first person game you could have your player character use SendMessage to send “OnPlayerInteracted” to objects when the player clicks the mouse. Then you can have any number of component types that implement that method in different ways without the player script having to know about all of them.
Naturally there are other mechanisms and architectures that can implement similar functionality, but SendMessage is available as a simple way to handle this type of decoupled communication.
Also, when using SendMessage, you don’t have to bother calling GetComponent; you can just call it on the GameObject itself which will invoke it on all the components which is how you keep the scripts from being coupled together.