and it throws a “MissingMethodException: The best match for method Seed has some invalid parameter.” even though I have a method Seed that accommodates the parameter of the Plate.plateParameterBlock type. In fact, the call seems to work, but it throws the exception nonetheless.
Interestingly, if I use SendMessage instead of BroadcastMessage, there is no problem at all - though it does not have the functionality I need
Hmmmm… Off the top of my head, without seeing all of your code… Is Plate.plateParameterBlock defined differently in each script? What data types did you declare for Plate.plateParameterBlock? Integer and string?
You seem to misunderstand. The problem is not in the execution of the function. The exception is thrown because the system tells me that my Seed() method would not match, when in fact it does. At least as far as I can tell. Just for reference, here is the complete error message
MissingMethodException: The best match for method Seed has some invalid parameter. System.MonoType.InvokeMember (System.String name, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object target, System.Object[ ] args, System.Reflection.ParameterModifier[ ] modifiers, System.Globalization.CultureInfo culture, System.String[ ] namedParameters) (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System/MonoType.cs:520) UnityEngine.SetupCoroutine.InvokeMember (System.Object behaviour, System.String name, System.Object variable) UnityEngine.GameObject:BroadcastMessage(String, Object, SendMessageOptions) CharGenController:SetState(CharGenState) (at Assets/Character Generation/Scripts/CharGenController.cs:44) CharGenController:Start() (at Assets/Character Generation/Scripts/CharGenController.cs:26)
I understand - I just don’t understand why you’re getting that message. I got a constructor error for new Plate.plateParameterBlock(0, “Value is 0”); , so I wrote it like this and it worked fine, no errors - even with a value of 3. [ 3 doesn’t work. see next post. - my bad, typo ] Not efficient, but it works. I’m out of ideas as to why you’re getting the error message.
using UnityEngine;
using System.Collections;
public class ThisScript : MonoBehaviour {
public GameObject go;
// Use this for initialization
void Start () {
SeedMe();
}
// Update is called once per frame
void Update () {
}
void SeedMe() {
Debug.Log ("SeedMe");
Plate.plateParameterBlock curPlate0 = new Plate.plateParameterBlock();
curPlate0.Index = Plate.PlateTypes.PT_GEN_DESCRIPTION;
curPlate0.Text = "Value is 0";
go.BroadcastMessage ( "Seed", curPlate0, SendMessageOptions.RequireReceiver );
Plate.plateParameterBlock curPlate1 = new Plate.plateParameterBlock();
curPlate1.Index = Plate.PlateTypes.PT_GEN_DESCRIPTION;
curPlate1.Text = "Value is 1";
go.BroadcastMessage ( "Seed", curPlate1, SendMessageOptions.RequireReceiver );
Plate.plateParameterBlock curPlate2 = new Plate.plateParameterBlock();
curPlate2.Index = Plate.PlateTypes.PT_GEN_TITLE;
curPlate2.Text = "Value is 2";
go.BroadcastMessage ( "Seed", curPlate2, SendMessageOptions.RequireReceiver );
Plate.plateParameterBlock curPlate3 = new Plate.plateParameterBlock();
// this is the typo...
curPlate3.Index = Plate.PlateTypes.PT_GEN_TITLE;
// and this generates an error message
curPlate3.Index = 3;
curPlate3.Text = "Value is 3";
go.BroadcastMessage ( "Seed", curPlate3, SendMessageOptions.RequireReceiver );
}
}
using UnityEngine;
using System.Collections;
public class Plate : MonoBehaviour
{
public enum PlateTypes { PT_GEN_ILLEGAL, PT_GEN_DESCRIPTION, PT_GEN_TITLE };
public struct plateParameterBlock
{
public PlateTypes Index;
public string Text;
};
void Seed( ref plateParameterBlock ppb )
{
Debug.Log("ppb.Index = " + ppb.Index);
Debug.Log("ppb.Text = " + ppb.Text);
}
}
EDIT for above. It doesn’t accept 3. It doesn’t like it. as you see above, I didn’t put 3. This is the error message if I put in 3:
Assets/Forum Help/ThisScript.cs(38,27): error CS0266: Cannot implicitly convert type int' to Plate.PlateTypes’. An explicit conversion exists (are you missing a cast?)
Thanks for trying. I am truly surprised I am getting this weird error message myself, especially because it works fine when I use SendMessage as opposed to BroadcatMessage. Sadly I have to use Broadcast because I need it to trickle down to the children.
Seems I figured it out. It had to do with function overloading.
I had Seed functions in a number of objects, each differentiated only by the argument passed into it. I thought the system would be smart enough to pick the right one, but evidently that’s what threw off the system. When I rename each of these Seed functions it works fine.