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.
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.
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";
}
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âŠ
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
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.