Hi, I’m having an issue I wasn’t having earlier. I’ve created a class with a mesh, which has a box collider. The problem is, I can’t set simulate physics to true on my mesh component in BeginPlay(), or by calling a custom function. The only way I can set physics is in the constructor, but that fires a warning after exiting PIE mode. In my EnablePhysicsOnRoot function I used to debug a bit, the physics aren’t enabled, I am also not getting “MeshComponent NOT found”, but I AM getting “EnablePhysicsOnRoot Fired” Message, as well as “MeshComponent Found”. On an earlier project I was able to call this in BeginPlay with no issues. Any help is appreciated.
#pragma once
#include "GameFramework/Actor.h"
#include "PhysicsActorTest.generated.h"
/**
*
*/
UCLASS()
class APhysicsActorTest : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY()
TSubobjectPtr<UStaticMeshComponent> MeshComp;
UFUNCTION()
void EnablePhysicsOnRoot();
//Override Functions
virtual void BeginPlay() OVERRIDE;
virtual void Tick(float DeltaSeconds) OVERRIDE;
};
// PhysicsActorTest.cpp
#include "CompTest.h"
#include "PhysicsActorTest.h"
APhysicsActorTest::APhysicsActorTest(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
static ConstructorHelpers::FObjectFinder<UStaticMesh>Mesh(TEXT("Static'/Game/Meshes/MyMesh.MyMesh'"));
MeshComp = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, (TEXT("Mesh")));
MeshComp->StaticMesh = Mesh.Object;
RootComponent = MeshComp;
PrimaryActorTick.bCanEverTick = true;
}
void APhysicsActorTest::BeginPlay()
{
Super::BeginPlay();
APhysicsActorTest::EnablePhysicsOnRoot();
}
void APhysicsActorTest::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
}
void APhysicsActorTest::EnablePhysicsOnRoot()
{
if (MeshComp)
{
MeshComp->SetSimulatePhysics(true);
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, TEXT("MeshComponent found!"));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, TEXT("MeshComponent not found!"));
}
GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, TEXT("EnablePhysicsOnRoot Fired."));
}