I’m creating 2 Instance Static Mesh Component, the first one called “box” and I created 3 instances in different locations. Now what I want is to create an instance of my second Instance Static Mesh Component called “test” and place it in the same location as any of the 3 instances of my first Instance Static Mesh Component called “box”. I’m using a property called “GetInstanceTransform” which brings me the location. but when stablesco for example 1 or 2 in the “instanceindex” returns me another location, since the size of “box” and “test” is not equal, but if I set the “instanceindex” to 0 if I set the location of my instance “test” correctly.
my code:
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
dommyroot = CreateDefaultSubobject<USceneComponent>(TEXT("dommyroot"));
RootComponent = dommyroot;
struct ::ConstructorHelpers::FObjectFinder<UStaticMesh> MyCube(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
box = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("box"));
box->SetStaticMesh(MyCube.Object);
box->SetupAttachment(dommyroot);
box->SetRelativeScale3D(FVector(1, 1, 1));
box->SetRelativeLocation(FVector(0, 0, 0));
struct ::ConstructorHelpers::FObjectFinder<UStaticMesh> MySphere(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
test = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("test"));
test->SetStaticMesh(MySphere.Object);
test->SetupAttachment(dommyroot);
test->SetRelativeScale3D(FVector(0.5, 0.5, 0.5));
test->SetRelativeLocation(FVector(0, 0, 100));
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
const FVector PizoLocation = CajaPincel->GetActorLocation();
dommyroot->SetWorldLocation(FVector(PizoLocation.X - 500, PizoLocation.Y - 500, PizoLocation.Z + 300));
for (size_t X = 0; X < 3; X++)
{
box->AddInstance(FTransform(FVector(X * 250, 0, 0)));
}
FTransform FTransformA; box->GetInstanceTransform(1, FTransformA, false);
const FVector FVectorA = FTransformA.GetLocation();
test->AddInstance(FTransform(FVector(FVectorA.X, FVectorA.Y, FVectorA.Z)));
}
now the following
for example: if I set the “instanceindex” to 0
FTransform FTransformA; box->GetInstanceTransform(0, FTransformA, false);
const FVector FVectorA = FTransformA.GetLocation();
test->AddInstance(FTransform(FVector(FVectorA.X, FVectorA.Y, FVectorA.Z)));
now if for example I set the “instanceindex” to 1
if I reset the “SetRelativeScale3D” with the same values it does it correctly, but when changing “SetRelativeScale3D” of “test” that happens. Any idea how to fix it? will it be that I am not establishing the correct function to do it?
PD: sorry but I do not speak English