Who calls OnUserInput?

HI i am new to unity and this course

i was wondering who calls OnUseinput message because i cant use it in other project. It makes me want to find out

After a hour of search

i found the function is called in class keyboard The Update function

which links to Terminal.ReceiveFrameInput then calls inputBuffer.ReceiveFrameInput

and when ‘\n’ is entered it calls sendcommand function of the inputbuffer class

where i found the OnCommandSentHandler event which adds NotifyCommandHandlers to it in awake of terminal script

But i have difficulty understanding the NotifyCommandHandlers function

 var allGameObjects = FindObjectsOfType<MonoBehaviour>();
        foreach (MonoBehaviour mb in allGameObjects)
        {
            var flags = BindingFlags.NonPublic | BindingFlags.Instance;
            var targetMethod = mb.GetType().GetMethod("OnUserInput", flags);
            if (targetMethod != null)
            {
                object[] parameters = new object[1];
                parameters[0] = input;
                targetMethod.Invoke(mb, parameters);
            }
        }

I know it is about search every object in the game and get the method called OnUseInput then call it.
But i cant find GetType().GetMethod these thing in unity document under monobehavior class ,so i have no clue how to understand them.

Anyone know how to find the reference of System.Reflection and the usage of gettype() getmethod() thing?

1 Like

Hi @Xyvansuba,

There’s a couple of things to consider here;

Firstly, you’ve been given an existing project which contains classes and, as you’ve found, the OnUserInput method is actually part of the code you’ve been given, as opposed to built-in to Unity.

Secondly, C# is a language in its own right, outside of Unity. If a class doesn’t derive from a Unity-based namespace such as UnityEngine / UnityEditor, and assuming you are not incorporating code from elsewhere (other projects/libraries/assets etc), chances are the classes will all be found within the C# .Net library.

Hope this helps :slight_smile:


See also;

Thx Rob. now i know where to find the answers

1 Like

You’re very welcome. Any other problems, just post, someone will typically always help you out :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms