Developer Console: Edit GameObject via Cmd-Line

I am finding it hard to explain but how would a implement the ability to edit a gameobject by typing its name into the comd-line?

I have found a Dev-Console by someone else with a video to show you what i mean, below.

Look at 1 minute in: Example at 1 Minute in

It’s possible to make, but it is a lot of work.

Take this example (from the video):
Soilder.Transform.set_position 1,1,1

First you need to extract the GameObject (here, Soilder).
And then you need to extract the Component (here, Transform).
When you are so far, then you need to extract all the methods from the component:

System.Type componentType = currentComponent.GetType();
MethodInfo[] methodArray = componentType.GetMethods();

The methodArray variable, contains all accessable methods for the component.
So you need to find which element in the method array, is the method you want to invoke (send). Now when you have the proper method name, you can use it to invoke that message:

object vectorvalue = new Vector3(1.0f, 1.0f, 1.0f);
object returnObject = methodArray*.Invoke(currentComponent, new object[] {vectorvalue});*

The set_position needs to have a vector3 as a inparameter, so you need to convert your Vector3 into a object. But the Invoke method needs a array of objects, so you need to add it into a object array.
The code above is just a brute example, and you shouldn’t use it, but write your own functionality.
if you want to make a console window, you need to make it more dynamic so that each method gets the right inparameters, and the methods which returns a value take that value and convert it into what you want. In my example above, the method has a returnObject, but set_position doesn’t return any value, but get_position would return a Vector3.
(EDIT: Added extra text here which I first wrote in the comments below.)
The example I gave above doesn’t include script specific methods, meaning functions from scripts you add yourself to a gameobject.
In order to access those scripts, you need to find the scripts through assembly. Something like this:
Assembly[] referencedAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();

// find the right component
System.Type currentComponentType = referencedAssemblies*.GetType(ComponentType);*
if (currentComponentType != null)
MethodInfo[] temp = currentComponentType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
First you get the assemblies, and you go through them all, looking for the right component, which the method is attached to. When you found that assembly reference, you need to get the methods from it with the function GetMethods. Check the inparameter flags so you get the right ones.
Good luck!

I was going to build a Developer Console in my previous project, but I scrapped that one and instead am planning to implement it in my current project. I did not get a chance to build it, but my untested plan was to:

  1. Create a script that handles all GUI functions. We’re talking like pressing the ESC key to pause the game, or the tilde key (since it is usually the tilde key, which if you don’t know is the ~ key on the keyboard) to bring up the developers console.
  2. Create the GUI itself which displays different elements depending on the key presses and whatnot.
  3. Create a “dictionary” so to speak that recognizes certain custom commands. So if I use another game for example, a command could be like:

/spawn cube 64 player1

. The “dictionary” would realize certain things like:

  • The command started with /spawn, therefore, I know I must give
    something to the inventory of the
  • After /spawn, there are certain arguments I must be given, and the
    main argument that I need is the
    object to be spawned, therefore cube
    is the prefab I must spawn.
  • One of the arguments that is not needed, is the amount to spawn the
    player, becuase my default value is 1. However, this player placed a value after telling me what they wanted to spawn and said 64, so I
    will give them 64 cubes.
  • An argument that I do need is who the player is that I’m spawning these
    cubes for. That’s always said at the
    end of this command, and the last given
    piece of information was player1, so
    I will give player1 64 cubes.

Really, this could be a script that includes a plethora of functions that only the developers console would be able to read.

When you hook the GUI and the Scripts up, you should have a working developers console. How large the script that includes the functions is up to you, so it could take quite a while to test. The amount of functions depends on how detailed you want to be and how much freedom you’re willing to give the players. You should also look into security, since only specific processes on the local machine should be affected (unless your developing something for multiplayer, in which case, you definitely have to have security in your design) or whatever you’re planning as this again depends on the level of detail you’re planning for this part of the game.