void Start() { // HACK(KARAN): Force initialization of Car properties GameObject carGO = GameObject.FindGameObjectWithTag("SelfDrivingCar"); car = carGO.GetComponent <Car>(); car.Start(); sharedMemory = new Memory(); sharedMemory.AddSection("unityFlag", 1); sharedMemory.AddSection("pythonFlag", 1); sharedMemory.AddSection("carData", sizeof(float) * car.carControlsData.Length); sharedMemory.AddSection("pythonData", sizeof(float) * car.pythonData.Length); //NOTE(KARAN) : Reserve memory for images captured from all cameras GameObject[] customCameras = GameObject.FindGameObjectsWithTag("CustomCamera"); cameraModules = new CameraModule[customCameras.Length]; for (int i = 0; i < cameraModules.Length; i++) { cameraModules[i] = customCameras[i].GetComponent <CameraModule>(); // HACK(KARAN): Force initialization of each camera cameraModules[i].Start(); int imageWidth = cameraModules[i].settings.imageWidth; int imageHeight = cameraModules[i].settings.imageHeight; int bytesPerPixel = cameraModules[i].settings.bytesPerPixel; int imageSize = imageHeight * imageWidth * bytesPerPixel; string cameraName = cameraModules[i].name; sharedMemory.AddSection(cameraName + "ImageWidth", sizeof(int)); sharedMemory.AddSection(cameraName + "ImageHeight", sizeof(int)); sharedMemory.AddSection(cameraName + "BytesPerPixel", sizeof(int)); sharedMemory.AddSection(cameraName, imageSize); } //NOTE(KARAN) : Save the memory layout as a csv so that python can use it. string layoutCSV = sharedMemory.GenerateCSV(); File.WriteAllText(Application.dataPath + "\\sharedMemoryLayout.csv", layoutCSV); sharedMemory.file = MemoryMappedFile.CreateOrOpen(memoryName, sharedMemory.locationCounter, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.Inheritable); sharedMemory.cursor = sharedMemory.file.CreateViewAccessor(); sharedMemory.cursor.Write(sharedMemory.GetLocation("unityFlag"), (byte)0); }