Importing SimConnect to Unity

Hi folks,

I want to learn about Simconnect. I have skimmed through the originial SimConnect MSDN manual. What I want to do is learn to develop C# plugins through Unity3D. There is very little documentation for Managed SimConnect, can someone explain(or link to a post) on what I need to do to get started in Unity? I have tried to import SimConnect through both Visual Studio and unity, but if I use the Unity method, when I type this line:

using Microsoft.FlightSimulator.SimConnect

Unity tells me the type or namespace ‘flight simulator’ does not exist in the namespace “Microsoft”. I have imported SimConnect through Unity and also added it as a reference in Visual Studio.

Thanks!

1 Like

This will help you:

When you produce something, please update it here, good luck!

Thanks for the referral. Will definitely check it out!

What is it that you want to do. You have to use webassembly to get things ti work in game. Otherwise you just create some sort of ui to read and set variables and interact with the sim for an external app like Little Nav Map

Hi DaBigBoy,
I am also trying to access Simconnect from Unity, but after several days of reading forums I still have not been able to get it to work. I am stuck at the point where I get the message, "The type or namespace name ‘FlightSimulator’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?) " when trying to add the line “using Microsoft.FlightSimulator.SimConnect” . Have you managed to get it working? If so, how did you gat past this error? Did you find any useful documentation?
Thanks a lot.

Do you have an example Unity app code? I’m sure I can get it working

Hi ZenMusic,
Thanks for offering to help.

Below is the c# script used in Unity:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; // for text class

using Microsoft.FlightSimulator.SimConnect; //the Microsoft.FlightSimulator.SimConnect.dll file is included in the assets folder which is accessible to this script (although not currently usable as a namespace)
using System.Runtime.InteropServices;// for Simconnect

public class SimConnector : MonoBehaviour
{
public Text SimText;

// ConnectSim is called when user clicks on "Connect" button. A text object is updated when connected.
public void ConnectSim()
{
    // the code below is taken from the documentation and is apparently what is needed to connect
    SimConnect simconnect = null;

    const int WM_USER_SIMCONNECT = 0x0402;
    try
    {
        simconnect = new SimConnect("Managed Data Request", this.Handle, WM_USER_SIMCONNECT, null, 0);
    }
    catch (COMException ex)
    {

    }

    if (simconnect != null)
    {
        simconnect.Dispose();
        simconnect = null;
    }


    SimText.text = "Connected";
}

// Start is called before the first frame update
void Start()
{
    SimText.text = "Press Button to Connect";
}

}

You are missing a reference to FsConnect :slight_smile:

Q: Did you install the MSFS-SDK with Visual Studio installed before ? If not, install SDK again.

Q: If SDK ok, load project and go NuGet: to do that, Right Click on References, go Manage NuGet packages and find SimConnect in the browse tab:

Install the first one
 After that
 the using you want to do is not underlined in red
 I did not try things further, but I suppose this would solve your above issue


NoRedLine

Thanks ArcanePython.
I reinstalled the SDK to make sure and installed the FSConnect. I then got a warning about the processor and made sure I was using x64 in the configuration manager. The warning and red underline went away, but when I went back into Unity, the same error about “FlightSimulator” was there. When I went back into Visual Studio, the warning and red underline returned.
I tried copying the fsconnect folders that were created under the packages folder into the assets folder, but this did not make a difference.
Is there another step I also need to do?
Thanks a lot for your help and time.

Nice
 SDK is up to date and x64 set (I forgot) so it should work now
 if you open your Unity Project, then NuGet will not work ? My tip was not to go copy directories manually, much better is the official way: go rightclick on your References and choose manage Nuget packages
 with VS, if you try to get things complete with copying files,. you will not get all dependencies ! And Nuget also checks for version differences.

btw I am not familiar with Unity. It is programmed in C# but I don’t know the dependencies.

Have you read this ? there’s example code
 I put a like right away !!

I installed the library as you described through the NuGet Package Manager, but when I was still having a problem in Unity I also tried copying the installed folder to the “Assets” folder, a location that Unity can access. I was still getting the red underline in Visual Studio (VS) as well. I added a reference in VS to the Microsoft.FlightSimulator.SimConnect.dll through the VS Project | Add Reference menu option and this removed the red underline in VS. However going back into Unity it still did not recognise the dll.
I seems that Unity does the compiling and VS is just an editor. I don’t know if I need to compile my own dll in VS and use that in Unity.
I took a look at the demo link you suggested. Maybe this will give a clue as to what is needed but it seems that some development is needed to get Unity to interact with Simconnect.
I am surprised that no one has done this yet.

I’ve done some C# things with MSFS project files, why would I want to link my own 3d graphics :grin:

In VS, you normally build a \Packages directory in your solution directory using NuGet. All libs are placed there. Maybe you need to copy part of the \Packages also into Unity’s Assets ? This is my last tip


Success with it. I only tested the above in VS2019, pure C#. When you are “in Unity” there is some kind of script editor ?

Ok, I’ll try that.
Unity uses VC as its editor, but the compilation is done by Unity so Unity needs to have access to the libraries.
My aim is to “gamify” the simulator by adding on a parallel program that can be run while flying.
Thanks a lot for your help so far. If I make any progress I’ll update this thread so others can also benefit.
I’m still open to any other suggestions from anyone.

Hi,
I have also tried to import SimConnect to Unity without success. Have you succeeded?

1 Like

Hi, I am trying the same thing. Unfortunately, I have not yet managed to succeed. Can anyone help?