diff --git a/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/Vehicle.cs b/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/Vehicle.cs index 1463ff3ce7..e1bed34cfc 100644 --- a/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/Vehicle.cs +++ b/Unity/UnityDemo/Assets/AirSimAssets/Scripts/Vehicles/Vehicle.cs @@ -343,12 +343,26 @@ private void InitializeVehicle() { captureResetEvent = new AutoResetEvent(false); } - //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" + //Register capture cameras for this vehicle (recording / data capture). + //Each vehicle should own a child hierarchy tagged "CaptureCameras". + //Scene-wide FindGameObjectWithTag only returns the first match and breaks multi-drone simGetImages. + private GameObject FindChildWithTag(GameObject parent, string tag) { + if (parent == null) { + return null; + } + foreach (Transform transform in parent.transform) { + if (transform.CompareTag(tag)) { + return transform.gameObject; + } + } + return null; + } + private void SetUpCameras() { - GameObject camerasParent = GameObject.FindGameObjectWithTag("CaptureCameras"); + GameObject thisVehicle = GameObject.Find(this.name); + GameObject camerasParent = FindChildWithTag(thisVehicle, "CaptureCameras"); if (!camerasParent) { - Debug.LogWarning("No Cameras found in the scene to capture data"); + Debug.LogWarning("No CaptureCameras found under vehicle '" + this.name + "'"); return; }