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
- Editor crash on "PPtr<Shader>::operator Shader*() const" when checking in changes with a very long comment in Unity Version Control window
- [Ubuntu] Toolbar and menu items for Version Control lack spaces in text on Linux
- Unity Version Control window Pending Changes tab’s Item checkbox is unresponsive when clicked and the item list is empty
- Audio stuttering occurs when heavy processing is performed while OnAudioFilterRead is in use
- Inconsistent Node search results in VFX Graph
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.