Try to search your question here, if you can't find : Ask Any Question Now ?

Object Does Not Match Target Type in Unit using Reflection

HomeCategory: stackoverflowObject Does Not Match Target Type in Unit using Reflection
Avatarpushpa asked 2 weeks ago

I am trying to use Reflection (first time for me and I have looked through many of the other answers for this error and not found one that works for me)

Here is the Calling Method

void OnMouseDown(){
    string CardName = "GoldFate";

    Type classType = Type.GetType(CardName);
    Debug.Log ("Type: " + classType);

    MethodInfo theMethod = classType.GetMethod("Resolve"+CardName);
    Debug.Log ("MethodInfo: " + theMethod);

    theMethod.Invoke(this, null);

Here is the target:

public class GoldFate {
    public void ResolveGoldFate(){
        Debug.Log ("We got to Gold Fate");

The output this generates is:

Type: GoldFate

MethodInfo: Void ResolveGoldFate()

TargetException: Object does not match target type.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:236)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
FateCardManager.OnMouseDown () (at Assets/Scripts/Card Manipulation/FateCards/FateCardManager.cs:53)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)

I do not get to the Debug Message obviously

Thanks in advance

1 Answers
Best Answer
Avatarnaveen answered 2 weeks ago
Your Answer

16 + 9 =

Popular Tags

WP Facebook Auto Publish Powered By :