Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2854: [UE4] simGetSegmentationObjectID will always return -1 #2855

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,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<UMeshComponent> 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<UStaticMeshComponent> comp; comp; ++comp)
{
int id = getCustomStencilForMesh(*comp);
if(id != -1)
return id;
}
for (TObjectIterator<USkinnedMeshComponent> comp; comp; ++comp)
{
int id = getCustomStencilForMesh(*comp);
if (id != -1)
return id;
}
for (TObjectIterator<ALandscapeProxy> comp; comp; ++comp)
{
int id = getCustomStencilForMesh(*comp);
if (id != -1)
return id;
}

return -1;
Expand Down