Search Unity

ObjectField is obselete, what's the new way?

Discussion in 'Scripting' started by tatelax, Jul 22, 2013.

  1. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    According to the console, this method of doing ObjectField is obselete,

    Code (csharp):
    1. character = (GameObject)EditorGUILayout.ObjectField(character, typeof(GameObject));
    So what's the new way? Can't find anything useful in the docs.

    I'm using C#

    Thanks!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The docs for ObjectField list the required parameters right at the top. Use one of those methods (there are three).

    --Eric
     
  3. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    Thanks, just had to add false at the end.
     
  4. yumupdate

    yumupdate

    Joined:
    Nov 20, 2012
    Posts:
    30
    I've been using MonoDevelop / C# and have found the intellisense to be extremely useful when filling out my functions. If you type in "SomeFunction(", as soon as you hit the first parenthesis, the first override of the function will show but you can use the up/down arrow keys on the keyboard to iterate through all the overrides. I think the problem with ObjectField is that it's first override (through the 3rd or 4th?) is Obsolete. Maybe they'll clean that up in future releases of Unity.
     
  5. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Great tip Eric, thanks. And great fix Tate! ("add false at the end!")

    The warning is a little obscure....
     
  6. chibiskuld

    chibiskuld

    Joined:
    Jan 27, 2018
    Posts:
    4
    Now, way way way out in 2020. I have found a solution for this, if someone shall happen to stumble upon this looking for something themselves:

    Code (CSharp):
    1.    
    2.     public int nOfMeshes;
    3.     public Mesh[] meshes;
    4.  
    Code (CSharp):
    1.    
    2.         nOfMeshes = EditorGUILayout.IntField(nOfMeshes);
    3.         meshes = new Mesh[nOfMeshes];
    4.         for ( int i = 0; i < nOfMeshes; i++)
    5.         {
    6.             meshes[i] = (Mesh)EditorGUILayout.ObjectField(meshes[i], typeof(Mesh), false);
    7.         }
    8.  
    This was what google pulled up as my first hit searching for an answer to this, so answering it in case.