I’m learning Unreal and I have an AActor
class with this constructor:
ABall::ABall()
{
// 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;
// Our root component will be a box that reacts to physics and interact with physical world.
UBoxComponent* BoxComponnent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComponnent"));
RootComponent = BoxComponnent;
BoxComponnent->InitBoxExtent(FVector(20.0f, 20.0f, 20.0f));
// Create a mesh componnent so we ca see where our ball is.
UStaticMeshComponent* BallVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BallVisualRepresentation"));
BallVisual->SetupAttachment(RootComponent);
// Enable collisions
SetActorEnableCollision(true);
BoxComponnent->SetCollisionProfileName(TEXT("BlockAll")); // or BoxComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
// Add a visual cuboid to see it.
static ConstructorHelpers::FObjectFinder<UStaticMesh> CuboidVisualAsset(TEXT("'/Game/Meshes/SM_Ball.SM_Ball'"));
if (CuboidVisualAsset.Succeeded())
{
BallVisual->SetStaticMesh(CuboidVisualAsset.Object);
static ConstructorHelpers::FObjectFinder<UMaterial> WhiteMaterial(TEXT("'/Game/Materials/M_White.M_White'"));
if (WhiteMaterial.Succeeded())
{
BallVisual->SetMaterial(0, WhiteMaterial.Object);
}
}
SetActorScale3D(FVector(1.0f, 1.0f, 1.0f));
}
I have draw the UStaticMesh
SM_Ball with a Box Brush and set it sizes to 20x20x20.
I don’t know how to set my ABall
actor size, but I set it to the BoxComponnent
to 20x20x20 but on editor appears double sized than UStaticMesh
:
But if I do this: BoxComponnent->InitBoxExtent(FVector(10.0f, 10.0f, 10.0f));
I get this:
Do I forget something?
Do I have to set Actor’s size on the constructor? or do I have to set UStaticMesh?
I have added SetActorScale3D(FVector(1.0f, 1.0f, 1.0f));
because I don’t know if it is an issue with scale.
By the way, this is the Static Mesh. Look at Approx. Size: