From fd2644125a3a259b0262294c91347c7d8b8c4187 Mon Sep 17 00:00:00 2001 From: shabpompeiano Date: Wed, 22 Mar 2023 13:03:39 +0100 Subject: [PATCH] Hotfix get images from multiple drones: simGetImages() was only returning images for one drone when asking for images from multiple drones --- .../AirSimAssets/Scripts/Vehicles/Vehicle.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/Vehicle.cs b/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/Vehicle.cs index 1463ff3ce7..b624d5eaee 100644 --- a/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/Vehicle.cs +++ b/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/Vehicle.cs @@ -343,10 +343,25 @@ private void InitializeVehicle() { captureResetEvent = new AutoResetEvent(false); } + private GameObject FindChildWithTag(GameObject parent, string tag) { + GameObject child = null; + + foreach(Transform transform in parent.transform) { + if(transform.CompareTag(tag)) { + child = transform.gameObject; + break; + } + } + + return child; + } + //Register all the capture cameras in the scene for recording and data capture. //Make sure every camera is a child of a gameobject with tag "CaptureCameras" private void SetUpCameras() { - GameObject camerasParent = GameObject.FindGameObjectWithTag("CaptureCameras"); + GameObject this_vehicle = GameObject.Find(this.name); + GameObject camerasParent = FindChildWithTag(this_vehicle, "CaptureCameras"); + if (!camerasParent) { Debug.LogWarning("No Cameras found in the scene to capture data"); return;