Adding these 3 lines to any MonoBehaviour script breaks it.

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.

#if false
'
#endif

Anyone else seeing this or is this pecualiar to my system.

Can’t confirm. Tried to put it in a monobehaviour in 2020.2.b2 and it still works.
Importing takes a suspicious while, though.

Arr bit of further testing seems it has to be in a namespace so this is fine:

using UnityEngine;

public class Bug : MonoBehaviour
{

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }
}
#if false
'
#endif

But this one doesn’t work:

using UnityEngine;

namespace TestSpace
{
    public class Bug : MonoBehaviour
    {

        // Use this for initialization
        void Start()
        {

        }

        // Update is called once per frame
        void Update()
        {

        }
    }
#if false
     '
#endif
}

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.

Hi @SpookyCat ,

We received your bug report for this yesterday and were able to reproduce the issue: Unity Issue Tracker - Unity doesn't recognise the script as Monobehaviour script when there's a grave accent in an #if false block inside a namespace

Thanks for reporting it! Please share related bug IDs in the future when you discuss issues on the forum, that makes it easier to follow up on them.

1 Like

@LeonhardP
Any chance this fix makes to LTS 2020 anytime soon?