Search Issue Tracker
By Design
Votes
0
Found in
2019.3.0b4
2020.1
2020.1.0a11
Issue ID
1195655
Regression
Yes
Can't add a script as a component when there are two classes with the same Name in the script but in different Namespaces
Can't add a script as a component when there are two classes with the same Name (one is a MonoBehaviour, the other isn't) in the same script , but in different Namespaces
Reproduction steps:
1. Open "PROJECT TO IMPORT ASSETS.zip" project
2. Try to add the "BreaksParser.cs" script as a component
3. A pop-up appears "Can't add script"
Expected Result: Script is added as a component as it has a valid MonoBehaviour in its second Namespace
Actual Result: Can't add a script as a component when there are two classes with the same Name, but in different Namespaces
Reproduced with: 2020.1.0a12, 2019.3.0b10, 2019.3.0b9, 2019.3.0b8, 2019.3.0b7, 2019.3.0b5, 2019.3.0b4
Did not reproduce on: 2019.3.0b3, 2019.3.0b1, 2019.3.0a1, 2019.2.12f1, 2018.4.12f1, 2017.4.34f1
Warning:
Class BreaksParser can not exist in multiple namespaces in the same file, even if one is excluded with preprocessor directives. Please move these to separate files if this is the case.
Note:
The issue doesn't repro in 2019.3.0b4 if last opened version was lower
Comments (6)
-
tellmandscouk
Apr 14, 2021 17:12
I tried to add the "BreaksParser.cs" as a component, but there I didn't get the pop-up.
-
sebas77
Apr 15, 2020 16:42
I don't know if this comment will be ever read, but this compiler warning is indeed generated also when monobehaviours are not used:
https://forum.unity.com/threads/annoying-compiler-warning-i-dont-think-is-correct.823116/
-
hellowill89
Dec 05, 2019 17:46
What will happen if the warning is ignored? Will anything break or be broken in the future?
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Player build freezes after calling Application.Quit() when the scripting backend is set to IL2CPP
- Texture is not applied on a Custom Render Texture when a Cubemap is selected as the texture
- 2D light leaks through ShadowCaster2D when ShadowCaster2D components are disabled then re enabled at runtime in Player builds
- Unity Hub redirects to The Unity Roadmap when navigating to “Send Feedback” option
- UI Toolkit throws warning and fails to clear references when fields are not typed as UnityEngine.Object
Resolution Note:
Currently this is by design. Only have one namespace and type in your file, if it inherits from MonoBehavior or ScriptableObject.
We have notified our documentation team about missing documentation in this area.