Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Object field in custom editor

Discussion in 'Editor & General Support' started by tribaleur, Feb 28, 2019.

  1. tribaleur

    tribaleur

    Joined:
    Jan 19, 2017
    Posts:
    34
    Hello,

    I'm trying to add a field to allow to choose an object in my custom editor but unfortunly it doesn't works.

    Here my custom editor code :
    Code (CSharp):
    1.  
    2. using UnityEditor;
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public override void OnInspectorGUI () {
    7.         Spell gameObject_Spell = (Spell)target;
    8. // ...
    9.  
    10.         gameObject_Spell.EffectArea = (EffectArea) EditorGUILayout.ObjectField("Effect Area", gameObject_Spell.EffectArea, gameObject_Spell.EffectArea.GetType(), true);
    11.  
    12. }
    But VisualStudio doens't recognize the signature EditorGUILayout.ObjectField(string, source, type, allowSceneObject) wich exist in the documentation : https://docs.unity3d.com/ScriptReference/EditorGUILayout.ObjectField.html

    And the must strange part is that i can see the signature in the autocompletion :
    upload_2019-2-28_10-2-47.png

    Does someone know why ?

    Thanks for your help.
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
    What is EffectArea? Is that a MonoBehaviour? Did you read the error message? What did it say?
     
  3. tribaleur

    tribaleur

    Joined:
    Jan 19, 2017
    Posts:
    34
    Ok i found what is the problem :
    The second parameter have to be a unity object ... this mean a UnityEngine.Object child and not a System.Object child.
    When you create a custom class, by default it's a System.Object child.

    Thanks for the help.