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. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    Dismiss Notice

Bug Case #1195655: Unity will not recognize a script as MonoBehaviour in specific edge case

Discussion in '2020.1 Beta' started by SugoiDev, Nov 5, 2019.

  1. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Another MonoBehaviour parser issue. Case #1195655


    This file will break the parser on a11 (at least)

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace RootNamespace.Namespace1 {
    4.     public class BreaksParser {
    5.     }
    6. }
    7.  
    8. namespace RootNamespace.Namespace2{
    9.     public class BreaksParser : MonoBehaviour {
    10.     }
    11. }
    I had never seen this used before, but saw it on an asset store plugin.
    The parser will think this is an invalid MonoBehavior because of the duplicated class name.
    If the Namespace1 class is renamed to something else, it will work.

    Anyone use used that "pattern" before?
    I think the usual is to have only a single namespace per file, but maybe there's a specific reason for doing that?
     
    LeonhardP and Peter77 like this.