Accessing Unity From Visual Studio without Unity IDE

I want to create a Visual Studio project that accesses the Unity framework.

To keep things clean and simple I want to avoid doing this inside of the Unity IDE, but completely inside of Visual Studio for now.

How can I achieve this? What assemblies and references do I need to make?
Is it even possible with Unity using mono?

Thanks.

I’m assuming you want to create a class library that could later be used in a unity project?

You’re going to need to reference the dll’s that are in the unity install directory, most likely:
C:\Program Files\Unity\Editor\Data\Managed.…

UnityEngine.dll is the first and most important.

UnityEditor.dll will be needed if you want to write editor scripts. Note, any editor scripts should be in their own library project separate from the game script library. And when imported into a unity project, you put it in an ‘Editor’ folder.

UnityEngine.UI.dll is another you might want for UI stuff, it’s in a different location though:
C:\Program Files\Unity\Editor\Data\UnityExtensions\Unity\GUISystem\UnityEngine.UI.dll

That should get you most everything you need.

Also remember to target .Net 3.5 or earlier, anything later than that won’t work correctly in Unity.

NOTE, this only lets you create libraries to be later used in a Unity project. You can not build an actual unity game only in Visual Studio.

Unity is a combination of mono/.net code and it’s own internal engine written in C++, and is intended to run a custom version of the mono runtime that Unity includes with the build of the game.

1 Like

My specific implementation is for creating a bare bones client and server using Unity’s TransportLayer. Although I will eventually be using the class libraries in a Unity project (at least the client)… I will need to be able to run and debug them outside of the Unity IDE…is this also possible?

Thanks BTW

They’ll have to be used in unity projects, as far as I know you can’t build a unity (server or client) with out Unity.

If you wanted a server that didn’t have the unity engine included in it, it would only be usable for messaging. It would not handle unity object types.

And no, you won’t be able to directly debug.

The dll’s I reference are made up of classes that primarily forward calls into the unity runtime. If no unity running, nothing to forward to.

It seem I might have just wasted the last few hours when I hit the “ECall methods must be packaged into a system module”

“The Unity transport layer currently cannot be used outside of the Unity Engine. There are plans for a separate independent UNet DLL with a C# API in a future release for applications like this.”

It’s absolutely crazy to expect you to develop a client and server networking environment inside of the Unity IDE as little scripts.

It doesn’t have to be little scripts. When creating classes through the unity IDE they just default as MonoBehaviour, you can change that. And if you create the classes while in Visual Studio opened through Unity, they’ll be created the default way in VS.

You can still write regular classes within unity. You just need to use Unity to do the final build/debug build.