Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug Cannot add an object to a serialized field, of which type is the class named 'Object'

Discussion in 'Editor & General Support' started by ailuropoda0, Jan 28, 2021.

  1. ailuropoda0


    Feb 26, 2020
    I have defined the class 'Object' in my namespace.

    And I have added a serialized field, of which type is the class 'Object'.

    In that case, I cannot attach a gameObject to the field in Unity editor.

    Code (CSharp):
    1. namespace Custom.Space
    2. {
    3.     public class Object : MonoBehaviour
    4.     {
    6.     }
    8.     public class B : MonoBehaviour
    9.     {
    10.         [SerializeField] private Object object;
    11.     }
    12. }
    It seems that the name of the class, 'Object' cannot be used as a type of a SerializeField
    If I have changed the name of class 'Object' with another name like' BaseObject', it works.
  2. Kurt-Dekker


    Mar 16, 2013
    Try choosing another name. Object already means UnityEngine.Object.

    Otherwise, disambiguate by providing the full name of the class, Custom.Space.Object

    In general Object is a TERRIBLE name to use, especially in Unity... I recommend staying away from it or you will be constantly bumping this ambiguity.