x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Problem when obtaining the location of my instances C++

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)));

alt text

now if for example I set the "instanceindex" to 1

alt text

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

Product Version: UE 4.19
Tags:
captura.png (269.2 kB)
captura2.png (260.7 kB)
more ▼

asked Feb 09 '19 at 08:42 PM in C++ Programming

avatar image

danielf94
32 2 3 9

avatar image danielf94 Feb 11 '19 at 01:47 PM

The problem occurs when the 2 "InstanceStaticMeshComponent" have different values in "SetRelativeScale3D" it always correctly returns the location of the first instance, but not the remaining one. Now if both have the same "SetRelativeScale3D" it works correctly.

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

You have to change the scale of the instances, not the scale of the InstancedStaticMeshComponent.

If you change the scale of the component, the locations are being scaled as well. So instead of

  test->AddInstance(FTransform(FVector(FVectorA.X, FVectorA.Y, FVectorA.Z)));

do:

  test->AddInstance(FTransform(FRotator(0.0f, 0.0f, 0.0f), FVectorA, FVector(0.5f, 0.5f, 0.5f)));

And remove the scale for the component.

more ▼

answered Feb 11 '19 at 02:35 PM

avatar image

SenseiHaketon
181 4 7 8

avatar image danielf94 Feb 11 '19 at 02:47 PM

Thank you very much, if I am grateful.

(comments are locked)
10|2000 characters needed characters left

By default you can not create an object of an abstract base class because the ABC acts like a blueprint on which you create your actual implementation shareit.

more ▼

answered Feb 21 '19 at 01:18 PM

avatar image

Ronald2131
1

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question