I am trying to create a sphere with a 1 kg mass, then print this mass to the log in the actor Tick function. The actor mesh mass is being initialized at 1 kg, but when I print the mass using the GetMass() function, I always get 0.000…
Any idea how this could be fixed? Thanks.
MyActor.h
#pragma once
include “CoreMinimal.h”
include “GameFramework/Actor.h”
include “MyActor.generated.h”UCLASS()
class MYPLUGIN_API AMyActor : public AActor
{GENERATED_BODY()
public:
// Sets default values for this actor's properties AMyActor();
protected:
// Called when the game starts or when spawned virtual void BeginPlay() override;
public:
// Called every frame virtual void Tick(float DeltaTime) override; UPROPERTY() USceneComponent* Root; UPROPERTY(EditAnywhere) UStaticMeshComponent* Mesh;
};
MyActor.cpp
include “MyActor.h”
include “Components/StaticMeshComponent.h”// Sets default values
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; Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root")); RootComponent = Root; Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh")); Mesh->AttachTo(Root); Mesh->SetSimulatePhysics(true); Mesh->SetMassOverrideInKg("Mesh", 1.0, true);
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay(); UE_LOG(LogActor, Warning, TEXT("Hello World!"))
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime); UE_LOG(LogActor, Warning, TEXT("Actor location is: %s"), *this->GetActorLocation().ToString()); UE_LOG(LogActor, Warning, TEXT("Actor mass is: %f"), Mesh->GetMass());
}