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"

[C++] How do I scale down mesh or scale up collider correctly?

Here's what it looks like when I constructed them by default:

alt text

And here's what it should look like in the editor when I changed the mesh's scale size to 0.5 for each axis. Note that I did this in "Simulate" mode in the UE4 Editor.

alt text

I don't know how to scale down the mesh, or scale up the USphereComponent by 50% of its original scale value.

This is how it looks in my code:


 // Sets default values
 AObstacle::AObstacle(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UMovementComponent>(TEXT("ObstacleBasicMovement")))
      // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     this->TimerCountdown = this->TimerInitialValue = 3;
     //Uniform scale
     FVector Scale = FVector(1.0f);
     //Setting basic mesh and collider
     this->SphereCollider = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereCollider"));
     //this->SphereCollider->SetRelativeScale3D(Scale * 2.0f);
     this->SphereCollider->SetWorldScale3D(Scale * 1.5f);
     static ConstructorHelpers::FObjectFinder<UStaticMesh> BodyMeshObject(TEXT("StaticMesh'/Game/Meshes/Sphere_Mesh.Sphere_Mesh'"));
     if (BodyMeshObject.Succeeded()){
         this->BodyMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("BodyMesh"));
     //Other properties
     this->Acceleration = FVector::ZeroVector;
     this->Velocity = FVector::ZeroVector;

I had tried to use SetRelativeScale3D() and SetWorldScale3D(), but it doesn't seem to scale my components, even when restarting UE4.

What am I doing wrong? Thanks in advance.

Product Version: Not Selected
ue4_ball.png (334.9 kB)
ue4_ball2.png (231.6 kB)
more ▼

asked Apr 09 '15 at 03:08 AM in C++ Programming

avatar image

293 31 30 91

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You code is in the class constructor, mainly this sets the "default" value for your object when you put it in your scene. SetWorldScale3D and SetRelativeScale3D will both work, if you use them inside BeginPlay() or OnConstruction() function.You can override these like so:

 virtual void BeginPlay() override;
 virtual void OnConstruction(const FTransform& Transform) override;

The BeginPlay() function will be called when the game starts. The OnConstruction() function is called whenever you change a property to the object. This include in the editor, so if you want this to be applied while in the editor, you can do that there.

So, for example, you can do that to do your scaling :

 void AObstacle::BeginPlay()
          //Uniform scale
          FVector Scale = FVector(1.0f);
     SphereCollider->SetWorldScale3D(Scale * 1.5f);
 //or you can do that:
 void AObstacle::OnConstruction(const FTransform& Transform)
     if (SphereCollider)
            FVector Scale = FVector(1.0f);
                   //Here you could replace your hardcoded 1.5f for a public variable exposed in the editor...
                SphereCollider->SetWorldScale3D(Scale * 1.5f);

Also, you don't need to use "this->" everywhere, it's not necessary.

more ▼

answered Apr 09 '15 at 03:00 PM

avatar image

2.1k 70 37 259

avatar image asperatology Apr 11 '15 at 07:58 PM

The this-> is a habit of mine dating back to Java programming where it was encouraged to use it mostly for referencing objects.

Thank you for your answer.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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