Integrating Unity Engine build with Unreal Engine

Hi, I have to link a Unity project with Unreal. Basically Unity project is supposed to give me input (in bool) according to which i will execute some events in Unreal project. Does anyone have any idea how to begin and implement this. An example provided will be greatly appreciated.

Also can someone tell me if i can use Kinect2 Xbox controller in Unreal?

Thanks :slight_smile:

You’re going to have to implement some kind of networking layer in both.

A bigger questions is - why would you do this?

Just to make things clear…
Are you talking about the C++ object “unity builder” or are you talking about the Unity game engine?

Oh ■■■■, that’s going to be a tough challenge. I hope your networking and serialization skills are good! This is a solvable problem, but it’s going to take you a really long time.

Basically, what you have to do is manually maintain synchronized game states between a Unity based game and an Unreal based game and have a universal way for games on both engines to talk to each other. To do that, you’ll have to do the following:

  1. Choose a networking protocol (TCP/IP or UDP) and encode your data packets for that protocol. You’ll have to structure your data to be engine agnostic, so if Unity or Unreal wants to wrap network data in an encapsulation layer, you’re going to have to strip that engine metadata away.

  2. You’ll need to decide on a universal serialization schematic. Your game objects will need to be serialized and deserialized exactly the same way on both Unity and Unreal. You’ll also need to have a metadata scheme.

  3. Your server is going to need to know what engine platform connected clients are using so that you can send properly formatted network data.

  4. If any section of server side or client side code changes on either engine, you will need to update your net code. Otherwise, you lose game sync.

  5. You’re almost certainly going to have to dive into the engine code or create your own networking plugin.

Seriously though… this is going to be a long and painful effort. There are no silver bullets; There are no easy solutions. As amber said, “Why would you doing this?”. What difference does it make to the end user whether they are using a UE4 game client or Unity game client? Just pick one and stick with it.

PS. Just to illustrate that it’s 100% possible, look at the HTTP protocol, browser clients and web servers. You can have different web servers and different browsers, but what is used on either end doesn’t matter because both browsers and servers use the HTTP protocol which is a universal standard. There isn’t an HTTP equivalent for game engines, so you’ll have to create your own protocol and wrap it in TCP/IP.

No, this is actually pretty easy to do if he is talking about Unity game engine.
Both UE4 and Unity support C++ plugin, all one has to do is make sure both games are running from the same folder, build a UE4 Plugin which loads an external DLL built on Visual Studio, do the same in Unity then both applications can communicate using that DLL as a bridge; I’ve done this just for fun some year back; I’ve pushed floats, ints, FText, FNames, FStrings forth and back when I was learning the UE4 Plugin environment.
An even easier way to do it is using SQLite as a local data cache since Unity has it builtin with .NET and there’s a C header of SQLite that can be used inside UE4’s C++.

Unity game engine :slight_smile:

I have a kinect program coded in unity and another project made in Unreal, So i wanted to somehow link the two of them together.

i’m a she :slight_smile: My project is supposed to update the dll according to the user inupt at RUNTIME and then be used in unreal. Do you have the project i can look into to get me started :).

PS: Glad you have have done this :smiley:

I am looking into these tutorials: https://www.youtube.com/watch?v=bTQ0WOPOhtY, good enough?

No, I don’t have those files anymore.
And no, that video shows how to make a C# dll, you can’t use it in Unreal unless you make a C++/CLI dll and perform “marshaling” to convert types from native to .NET and vice-versa.

You have to look for “how to make native plugins” in Unity instead.

When sending text data from Unreal you’ll want to convert your data using TCHAR_TO_UTF8(*MyFString) macro, when sending text back to Unreal you use UTF8_TO_TCHAR(MyCharArray.c_str()) or ANSI_TO_TCHAR(MyCharArray.c_str()), where “MyCharArray” is a string you can return from an external dll function.
Ints and floats, bools or byte work just fine no need for conversions;

But if you’ve never built dlls before this may be a bit little daunting of a task.
Here’s some useful info on the topic:

https://forum.unity.com/threads/communicating-c-with-c.89930/

So if i only need two bools from the c# dll (ie: from unity project. Notice i only want to read from Unity and not Unreal so the network is one way), isn’t it better to do now just call it in C++ (because i have already made a C# dll successfully that updates from Unity program :)). For that i assume i have to make a C++ dll and that read values in the Unreal project from there. Am i getting this right?

No, you have to build an “observer” process which is the program you use to share the data (using the same dll code) OR you store the data somewhere, this is why I mentioned SQLite.

If all you want to check is just a “bool”
Both engines have access to System IO.

You can write a file to disk (anything) then in Unreal you check if file exist… Hacky but works.

You can launch your Unity game (through the UE4 plugin built) as a child process and communicate directly (via the external dll functions)…

You can use JSon on both engines, etc.
there’s a lot of options.

Oh i love your writing file to a disk idea, seems so simple :D. i assume we can even write and read simple text files this way from both engines right? i’m actually a noob in unreal, haven’t even started working on it.

But i think instead of running two instances i should focus on launching Unity through Unreal.

Yes, Unreal has a file helper static class to read/write files:

https://wiki.unrealengine.com/File_M…iles,_and_More

Another thing that is possible on Windows is to use the WinAPI in Unity to fire a Windows Event, then on Unreal use “WaitForSingleObject” Windows function to capture that event and execute code in your UE4 game: