Using RakNet in Unity

Hi, I'm trying to get RakNet (latest version) to work in Unity. I want to write my own custom networking using it and I haven't been able to get it to work so far. I generated a C# DLL with swig and RakNet, but how do I use it? Where do I put it, and how can I call to/from it?

I tried to place the DLL in my Assets folder, but whenever I put using RakNet; (As it says to do for C# scripts in the RakNet manual) in my script, it tells me the namespace can't be found. Doug 0 secs ago

Oh and, I don't need pro to do this, correct?


Yes, you don’t need Pro to do this.

Unity uses an subset of .NET 2 (see under PlayerSettings) with some features of the 3.5. Check if your dll is compiled for .NET 2, technically you can also use 3.5 but you need to be careful with compatibility of some functions and classes not supported by mono.

My sugestion is try to change to .NET 2 instead of an subset if the error persists, try to port your dll to .NET 2, that maybe tricky.

Try also paste all your code inside the unity (i recommend an empty project) and you will see with parts of your code needs change, fix them all, then compile the dll again with this new code.

Check this Unity - Manual: Managed plug-ins.

Just so ppl know, raknet.dll must go in the root project directory and it seems also in the assets folder, and when you build the project, put it in the same folder as the exe

I eventually after 8 hours of trial and error got it built for windows.