Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Call native Unity code from WPF application

Discussion in 'Windows' started by Tecgraf, Jul 5, 2018.

  1. Tecgraf

    Tecgraf

    Joined:
    May 11, 2018
    Posts:
    1
    Hello community!

    I've just started a new project and one of its requisite is that it works inside a WPF/UWP app. Now my team is debating whether we should go with one or the other.

    So far Unity already has support for UWP/Xaml build, doing native window embedding and with native Unity code being called from the UWP app (which is nothing short of amazing btw).

    But UWP has its owns drawbacks and we wanted to create a test WPF app. I already know how to embed Unity into a WPF app and that, generally, the communication works with json serialization and shared memory.

    The question here is if its possible to call native Unity code from within a WPF app, just like I can call native Unity code from an UWP app.

    I was thinking on trying to reverse engineer the Xaml/UWP solution built by Unity (during the build process) to make it work for WPF, but that seems a way too long shot.

    Has anyone tried this before? Is it possible?

    Thank you all!
     
    Last edited: Jul 5, 2018
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,644
    UWP/XAML embedding will always be totally different to WPF embedding. If you look at Unity's installation directory under Editor\Data\PlaybackEngines\WindowsStandaloneSupport\Source, you'll find the source code for the .exe file that we copy when you make a build. You can look at how it calls into Unity and swap out the executable with your own in a built game.