Scale Object and Keep its Position?

Hello,

I am trying to scale my 3D objects, however when I scale them in code, they always move along an axis and changes its original position.

How can I simply resize (scale) my object while keeping it in its original location?
I am trying to create a 3D map that is tiled with different tile sizes. The end result is my tiles are displaced when scaling.
Also, it shouldn’t be my code?.. The unscaled squares are exactly where they should be.

Quick demonstration of the problem:

	FTransform InstanceTransform;

	for (int x = 1; x <= 10; x++) {
		UInstancedStaticMeshComponent* BlockCopy;
		BlockCopy = NewObject<UInstancedStaticMeshComponent>(BlockInstance);
		FVector SpawnLocation(x*100, 1, 0.f);
		InstanceTransform.SetLocation(SpawnLocation);
		BlockCopy->AddInstance(InstanceTransform);
		if (x > 5 && x < 8) {
			BlockCopy->SetWorldScale3D(FVector(2, 2.f, 1.f));
		}
		else if (x >= 8) {
			BlockCopy->SetWorldScale3D(FVector(1, 4.f, 1.f));
		}
		BlockCopy->SetStaticMesh(BlockMesh.Object);
	}

I expected this to create a straight solid line along the x-axis, but at the scaling points it breaks up. I have been stuck on this for awhile. Here’s an example of intended result:

135840-scale2.png

surely someone knows how to solve this? :slight_smile:

This is happening because you are adding an instance of the mesh which isn’t at the origin of the component, and then you’re scaling the entire component. As a result, the offset between the instance and the component (SpawnLocation) is getting scaled as well.

Using InstancedStaticMeshComponents is kind of pointless here since you’re only adding a single instance of the mesh to each component. Just use regular StaticMeshComponents and your problem will go away. Alternatively, transform SpawnLocation by the inverse of the block’s intended scale to offset the change in position caused by scaling the component.

how can this be done as a bp?