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

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

    ailuropoda0

    Joined:
    Feb 26, 2020
    Posts:
    9
    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.     {
    5.  
    6.     }
    7.  
    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

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,196
    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.