From 0dcfa92b389aea152e36b105b3def6e3f713a985 Mon Sep 17 00:00:00 2001 From: Christoph Reinbothe Date: Fri, 24 Jul 2020 01:02:27 +0200 Subject: [PATCH] Fixes #2854: [UE4] simGetSegmentationObjectID will always return -1 (#2855) --- .../Plugins/AirSim/Source/AirBlueprintLib.cpp | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp b/Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp index 653704fc41..58a8ea4f53 100644 --- a/Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp +++ b/Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp @@ -366,14 +366,33 @@ bool UAirBlueprintLib::SetMeshStencilID(const std::string& mesh_name, int object int UAirBlueprintLib::GetMeshStencilID(const std::string& mesh_name) { - FString fmesh_name(mesh_name.c_str()); - for (TObjectIterator comp; comp; ++comp) - { - // Access the subclass instance with the * or -> operators. - UMeshComponent *mesh = *comp; - if (mesh->GetName() == fmesh_name) { + // Takes a UStaticMeshComponent, USkinnedMeshComponent or ALandscapeProxy and returns their custom stencil ID if + // their meshes's name or their owner's name (depending on the naming method in mesh_naming_method_) equals mesh_name + auto getCustomStencilForMesh = [&mesh_name](auto mesh) -> int { + const std::string component_mesh_name = common_utils::Utils::toLower(GetMeshName(mesh)); + if (component_mesh_name.compare(mesh_name) == 0) { return mesh->CustomDepthStencilValue; } + return -1; + }; + + for (TObjectIterator comp; comp; ++comp) + { + int id = getCustomStencilForMesh(*comp); + if(id != -1) + return id; + } + for (TObjectIterator comp; comp; ++comp) + { + int id = getCustomStencilForMesh(*comp); + if (id != -1) + return id; + } + for (TObjectIterator comp; comp; ++comp) + { + int id = getCustomStencilForMesh(*comp); + if (id != -1) + return id; } return -1;