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
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Adding these 3 lines to any MonoBehaviour script breaks it.

Discussion in '2020.2 Beta' started by SpookyCat, Sep 21, 2020.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Just spent a fun day trying to find out why some of my scripts were no longer recognised by Unity as Components and MonoBehaviours, tracked it down to the rathert surprising fact that if you add the 3 lines in the code section to any Monobehaviour script at at position in that script Unity will no longer thing that it is a valid MonoBeheviour and will tell you the Class name or Filename are incorrect. This seems to happen on all 202 versions of Unity.

    Code (CSharp):
    1. #if false
    2. '
    3. #endif
    Anyone else seeing this or is this pecualiar to my system.
     
  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Can't confirm. Tried to put it in a monobehaviour in 2020.2.b2 and it still works.
    Importing takes a suspicious while, though.
     
  3. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Arr bit of further testing seems it has to be in a namespace so this is fine:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Bug : MonoBehaviour
    4. {
    5.  
    6.     // Use this for initialization
    7.     void Start()
    8.     {
    9.  
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.  
    16.     }
    17. }
    18. #if false
    19. '
    20. #endif
    21.  
    But this one doesn't work:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace TestSpace
    4. {
    5.     public class Bug : MonoBehaviour
    6.     {
    7.  
    8.         // Use this for initialization
    9.         void Start()
    10.         {
    11.  
    12.         }
    13.  
    14.         // Update is called once per frame
    15.         void Update()
    16.         {
    17.  
    18.         }
    19.     }
    20. #if false
    21.      '
    22. #endif
    23. }
     
  4. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    Tried it here and get the same thing the script is no longer seen as a Mono component when those lines are added to my script. That is a bit crazy, no problems in 2019 but 2020.1 and 2020.2 beta both have the problem.
     
  5. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,132
    brunocoimbra likes this.
  6. weber-jaroslaw-dmm

    weber-jaroslaw-dmm

    Joined:
    Mar 30, 2017
    Posts:
    14
    @LeonhardP
    Any chance this fix makes to LTS 2020 anytime soon?