AirSim icon indicating copy to clipboard operation
AirSim copied to clipboard

Unity Car/Drone Demo Crashes

Open bugrahanakbulut opened this issue 7 years ago • 6 comments

I have builded AirSim and builded sample Unity projects. But when I try to run CarDemo or DroneDemo directly, it crashes Unity. But running SimModeSelector, then selecting Car or Drone, does not crash Unity. I need to run CarDemo or DroneDemo directly without SimModeSelector, how can i do that? What can be the reason of crash? specs: Windows 10, Unity 2018.2.15f1, VS2017 15.8.9, SDK 8.1

bugrahanakbulut avatar Dec 10 '18 18:12 bugrahanakbulut

Same problem here.

jasonhbartlett avatar Dec 10 '18 19:12 jasonhbartlett

Same problem here.

MelSoS avatar Dec 11 '18 09:12 MelSoS

Unity requires simModeSelector to set necessary parameters for AirSim. The readme has been updated to remove instructions to open DroneDemo or CarDemo scenes directly.

@bugrahanakbulut, if you want to enter a sim mode directly, edit your json file accordingly.

 "SimMode" : "Multirotor"

Or:

"SimMode" : "Car"

msb336 avatar Dec 14 '18 02:12 msb336

@msb336 Just wanted to pass along another thing that could cause Unity AirSim to crash and a solution for fixing it. In this case the cause is if your trying to use PX4/SITL vs SimpleFlight. This isn't a problem with Unreal Engine and the setting file works fine if you have your Setting.json file configured for PX4 like so:

{
  "SettingsVersion": 1.2,
  "SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md",
  "SimMode": "Multirotor",
  "Vehicles": {
    "PX4": {
      "VehicleType": "PX4Multirotor"
    }
  }
}

But this currently causes Unity to crash. I believe the structs located in AirSim/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Utilities/AirSimSettings.cs script need to be updated to be able to read the "Vehicles" data structure. But until that happens, as a work around you can add "DefaultVehicleConfig": "PX4" to the settings file, like so:

{
  "SettingsVersion": 1.2,
  "SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md",
  "SimMode": "Multirotor",
  "DefaultVehicleConfig": "PX4",
  "Vehicles": {
    "PX4": {
      "VehicleType": "PX4Multirotor"
    }
  }
}

This does not effect the Unreal, so you can use the same settings for Unreal and Unity. There is one other thing I found I had to change however. In AirSim/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/VehicleCompanion.cs Line 45:

        public static VehicleCompanion GetVehicleCompanion(IVehicleInterface vehicleInterface) {
            var companion = new VehicleCompanion(vehicleInterface);

            if (AirSimSettings.GetSettings().SimMode == "Car")
                companion.vehicleName = "PhysXCar";
            else if (AirSimSettings.GetSettings().SimMode == "Multirotor")
                companion.vehicleName = AirSimSettings.GetSettings().DefaultVehicleConfig;
                //Above line replaces // companion.vehicleName = "SimpleFlight";
                
            Vehicles.Add(companion);
            return companion;
        }
companion.vehicleName = "SimpleFlight";

is replaced by:

companion.vehicleName = AirSimSettings.GetSettings().DefaultVehicleConfig;

And now I can use Unity AirSim with PX4 Software in the Loop and fly the drone using QGroundControl!!!

But this IS just a band-aid until the AirSimSettings.cs is updated to read the newer structs instead of trying to read DefaultVehicleConfig element which appears to have been removed back on May 17th with the following merge: 53cdcde41a9c325ba34d06b02a45d960bdb543ca

jasonhbartlett avatar Dec 14 '18 21:12 jasonhbartlett

Works perfectly fine, thanks!

MelSoS avatar Jan 03 '19 00:01 MelSoS

Glad to hear it @MelSoS ! If you have no further problems related to this issue, lets close it!

msb336 avatar Jan 03 '19 15:01 msb336