Using an exported project as a XAML UserControl

While I know that Unity projects are meant to run as stand-alone applications, I need to make something a little bit different and I need your help.

Basically I’d like to add a 3D scene to my app, which is not a brand new app so I can’t start from scratch, and since an Unity exported project will run into a SwapChainPanel I thought that I could just import it in my app and just use it.

This will be way easier than moving the project to Unity’s exported solution.

Final goal will be to export & compile Unity project and just update DLLs + project data into my main app to update Unity scene.

I did some tests but I wasn’t really lucky, so I feel that I’m missing something.

What I did was to copy all the references from the Unity exported project to my App project, then I moved assets and levels (keeping the same file structure) and finally I copied DLLs and Players folder.

Final result was the app crashing as soon as I loaded the page containing the SwapChainPanel, with an error about missing renderer in game manager (sorry for not being 100% accurate, I don’t have the project right now).

So, my question is: is there a way to export a Unity project as a XAML UserControl so that I can just plug it into an already existing app? Being an UserControl is not really mandatory, having it inside a page in my already existing page will be good for now, but I’d like to just use the Unity project inside my app.

What I was doing to embed a Unity application inside an application was the following:

  • Create WinForms control (should also work with WPF control, did not try that. if not use WinFormsHost)
  • Start unity process from code, passing the window handle with “-parentHWND” (see link)
  • Communicate to the process using IPC mechanisms

You can find more information about starting unity with commandline attributes on the linked page.

See the table almost at the end of the page (-parentHWND description), there is a little ZIP with an example project which was very helpful to me.

Depending on what “application” you have, the solution will be similar.

Regarding IPC i tried NamedPipes and SharedMemory with no luck so I’m currently sticking with TCP communication.

I also use DLLs from the Application and from within Unity. In order to do that I put the dll project output (dll file) inside the Unity assets so you can access it from unity c# code just as you would with other libraries.

It works but it is not very straight forward.

Thank you @InfiniBuzz

Your comments greatly helped to figure out how to use an unity application as a child app.

Truly, I have a small problem with the sample code. Since I am using Windows 10 Universal API, I can’t generate executable exe app. The app should be either deployed or installed :frowning:

Do you have any idea how I can bind app in Windows store API

Best Regards Reza

Can you tell me which version you were using?
Can you provide me with the source code too?
i am stuck with same kind of problems.
@InfiniBuzz