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"

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

alt text

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:

alt text

surely someone knows how to solve this? :)

Product Version: UE 4.15
Tags:
scale.png (160.4 kB)
scale2.png (1.8 kB)
more ▼

asked Apr 27 '17 at 09:34 PM in C++ Programming

avatar image

DaiWei
26 3 7 13

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

1 answer: sort voted first

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.

more ▼

answered Apr 28 '17 at 12:19 AM

avatar image

Teiwaz
619 26 28 54

avatar image Delta1 Sep 27 '18 at 11:12 AM

how can this be done as a bp?

(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