Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug I not trying creator a MonoBehaviour using the 'new' keyword, but editor console warning

Discussion in '2021.1 Beta' started by Ztail, Feb 26, 2021.

  1. Ztail

    Ztail

    Joined:
    Feb 24, 2018
    Posts:
    5
    warning info : You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all

    code:
    Code (CSharp):
    1. protected List<List<LayoutInfo>> layoutList { get; } = new List<List<LayoutInfo>>();
    LayoutInfo code:
    Code (CSharp):
    1. protected struct LayoutInfo
    2.         {
    3.             public RectTransform rectTransform;
    4.  
    5.             public Vector2 min;
    6.             public Vector2 preferred;
    7.             public Vector2 flexible;
    8.         }
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    Putting that code in an empty scene doesn't trigger the warning for me, so the warning is probably coming from somewhere else.