UInstancedStaticMeshComponent::GetInstanceTransform pointer problems

Hello world.

I’m trying to compare two different UInstanceStaticMeshComponents to see if they have any overlapping instances, then remove those instances from both.

The code

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?

____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

EDIT: For those who may come across this same problem, this is what the code, corrected, ended up looking like:

However, now new error arises - not at compiling, but at playing. The second for loop, wherein I try to get

ParentRect->WExtStraightMesh->GetInstanceCount()

crashes the game. No coherent error message is given by the error reporter. Thoughts?

There is missing araguments for “GetInstanceTransform” function

UFUNCTION(BlueprintCallable, Category="Components|InstancedStaticMesh")
bool GetInstanceTransform
(
    int32 InstanceIndex,
    FTransform & OutInstanceTransform,
    bool bWorldSpace
)

Try This

FTransform TransformA;
FTransform TransformB;

ParentRect->WExtStraightMesh->GetInstanceTransform(a, TransformA);
WExtStraightMesh->GetInstanceTransform(b, TransformB);

if(TransformA == TransformB)
{
//.....
}

Your method has fixed one bug…and I now face another.

		for (int b = 0; b < ParentRect->WExtStraightMesh->GetInstanceCount() - 1; ++b)

This line crashes the program, particularly the ParentRect-> part; if I just do WExtStraightMesh without it, there are no problems.

You bring up various points, which I had realized later and forgot to edit back into the post :stuck_out_tongue:

The code block is now as such:

	for (int a = 0; a < WExtStraightMesh->GetInstanceCount() - 1; ++a)
	{
		for (int b = 0; b < ParentRect->WExtStraightMesh->GetInstanceCount() - 1; ++b)
		{
			/*FTransform A; WExtStraightMesh->GetInstanceTransform(a, A); FVector AV = A.GetTranslation();
			FTransform B; ParentRect->WExtStraightMesh->GetInstanceTransform(b, B); FVector BV = B.GetTranslation();
			if (AV == BV)
			{
				WExtStraightMesh->RemoveInstance(a);
				ParentRect->WExtStraightMesh->RemoveInstance(b);
			}*/
			UE_LOG(LogTemp, Warning, TEXT("TEST2"));
		}
		UE_LOG(LogTemp, Warning, TEXT("TEST1"));
	}

and now there is a crash on play, with the second for line being the culprit (commenting it out fixes the problem). Thoughts?

,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.