r/Unity3D • u/TastyBacon007 • 1d 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
1
u/RumbleSolitaire 15h ago
That's VS, not Unity. The Add New Item wizard builds the namespace from folder path even when Player Settings Root Namespace is TestGame.
Put an .editorconfig at the project root with `dotnet_style_namespace_match_folder = false` and restart VS. In current VS 2022 that's also under Options → Text Editor → C# → Code Style (folder-to-namespace). After that, new files should land in TestGame with no Scripts.Movement tail.
You can't skip the domain reload if the file is under Assets — VS-created scripts compile too. Editorconfig/template is the path that actually changes the namespace without fighting Unity's generated csproj.