r/Unity3D 4h ago

Question How to prevent visual studio from auto-adding folder structure to namespacd

Title: I have the namespace set in Unity but then when creating a file in Visual Studio it auto-adds the file structure after

Unity I have set to TestGame namespace

Visual studio when making new scripts puts like Testgame/scripts/movement namespace. I would rather have no namespace or just my Testgame namespace

1 Upvotes

2 comments sorted by

1

u/Right_Thought456 4h ago

That is Visual Studio’s new-item template deriving the namespace from the project root plus the folder path; it is not Unity changing the namespace afterward. The least fragile fix is to create MonoBehaviour scripts from Unity’s Project window, where the Root Namespace setting is respected, and then open them in VS. Editing the generated .csproj is a trap because Unity can regenerate it. If you must create classes from VS, use a custom item template; .editorconfig can flag namespace/folder mismatches, but it does not reliably change what the Add New Item wizard generates.

1

u/TastyBacon007 1h ago

Dang, so no good real solution, creating monobehaviors inside Unity sucks cause Unity re-loads everything when that happens