I’m trying to compare two different UInstanceStaticMeshComponents to see if they have any overlapping instances, then remove those instances from both.
Gives me a C3867 error: 'UInstancedStaticMeshComponent::GetInstanceTransform': function call missing argument list; use '&UInstancedStaticMeshComponent::GetInstanceTransform' to create a pointer to member
I tried then to use
if (&ParentRect->WExtStraightMesh->GetInstanceTransform[b] == &WExtStraightMesh->GetInstanceTransform[a])
{
&WExtStraightMesh->RemoveInstance[a];
&WExtStraightMesh->RemoveInstance[a];
}
to no avail. How would I use pointers in this scenario?
Your code has multiple errors in it, both semantic and syntactic. In addition to errors that will prevent the code from compiling, it could also loop infinitely, and also not have the effect you want or do nothing at all.
The reason your code is also unlikely to work at all, even if you fixed all of the basic errors, is because you are comparing transforms, which consist of multiple floating point components. Unless you wrote the memory directly and then never touched it again with a fp operation, the comparisons are very much unlikely to ever be true. You would need to determine some epsilon/tolerance and then use that as a threshold for determining equivalency. There’s no way to know what that would be for your use case in isolation, so you would need to explain what you’re doing.
Here are your various problems anyway, in case you’re interested:
You’re using [] instead of () for a function call.
You’re removing from the same index twice with an operation that will move data around, so the second removal will either remove something undesired, or will do nothing, because the index will be invalid the second time and the code for RemoveInstance(…) will return false.
for (int a = 0; a < WExtStraightMesh->GetNumChildrenComponents(); ++a)
GetNumChildrenComponents() is completely unrelated to the number of mesh instances for the instanced mesh renderer.
for (int b = 0; a < ParentRect->WExtStraightMeshes->GetNumChildrenComponents(); ++b)
Unless the two ‘WExtStraightMeshes’ fields point to the same component (you should never do this with UActorComponents), the loop condition never changes. This will loop infinitely every time.
if (ParentRect->WExtStraightMesh->GetInstanceTransform[b] == WExtStraightMesh->GetInstanceTransform[a])
This will probably never evaluate to true, except under very specific circumstances (mesh instances were placed using code and then never serialized/deserialized or sent over the network, and never changed with any math operations).
,You are trying to modify collections whilst iterating over them and most likely walking off the end of one of them when iterating. And you are also skipping the next member when removing a member. You should only increment (++a, ++b) when not removing a member. That’s what I’m reading.