Retrieving an arbitrary script component by name and calling a method.

I’m uncertain if there’s a way to do this. I am trying to create a registry “manager script” in which game objects will be registered and the “client” script will pass its script name to the “manager” script which will later attempt to call functions by using “gameObject.getcomponent(scriptName).KnownMethodFunction();”

However, when I try to compile, it wants to know the destination script and be certain the method I try to call is actually extant. Since there’s any number of different scripts I would like this manager to be compatible with, I was wondering if there were a way to call methods on arbitrary components by their name. I would otherwise create a list of scripts, but this would require knowing in advance the “typecast” of the script rather than accessing it by GetComponent(string).

Any ideas how I can register arbitrary scripts with a universal registry script and then call an already known function name in those scripts?

Although I’m not sure I understood you. If you don’t know the name of method you will be calling in future at time of registering the script then when it’s time to call it how do you do it still not knowing what’s the method you want to call?

Also this way of calling is probably somewhere between rather and very slow.

EDIT: If you know the name of the method but you don’t know the type implementing this method then what you should do is have an interface defining this method and then have all the classes implement this interface. This will deal with the compiler error.

Though not precisely what I was looking for - it will adequately fit the purpose. Thanks a bunch!

EDIT: Also, sorry, I do know the name of the method I want to call, I just want to be able to assign an arbitrary monobehavior for it to be called on. Meaning, I will have anywhere from one to a thousand different monobehaviors, all with the same method name, but I won’t be able to declare the type.

I just looked up interfaces and they look like a much better way to do what I’m looking for. Thanks a bunch for your help.

Ignore the first suggestion and only take the EDIT. What you want is to implement a interface.
Calling a method by “name” (string) is usually a very bad idea. If you know that a specific type MUST have a specific method, then make an interface that enforce that method implementation.

public interface IMyInterface
{
    void KnownMethod();
}

public class MyType : MonoBehaviour, IMyInterface
{
    public void KnownMethod()
    {
         // Do something.
    }
}

public class MyManager
{
    public void InvokeKnownMethod(object myObject)
    {
        IMyInterface myInterface = myObject as IMyInterface;

        if (myInterface != null)
            myInterface.KnownMethod();
    }
}

I’m just somewhat new to this. The most readily apparent solution to my dilemma seemed to be "pass the name of the monobehavior script name to the manager by a string and use “GetComponent” to access the client script. “Interface” seems both more eloquent and more easily implemented. I appreciate the help.