UDestructibleComponent - Weird physics and no child position update

Hi!

I want to have some lightning destructibles falling down, so I wrote this:.

ATest::ATest()
{
	DestructibleComponent = CreateDefaultSubobject<UDestructibleComponent>("DMComp");
	Light = CreateDefaultSubobject<UPointLightComponent>("Light");
	DestructibleComponent->SetSimulatePhysics(true);
    GLog->Log(DestructibleComponent->IsSimulatingPhysics() ? TEXT("true") : TEXT("false")); // shows "false"
	RootComponent = DestructibleComponent;
	Light->SetupAttachment(RootComponent);
}

void ATest::BeginPlay()
{
	Super::BeginPlay();
	GLog->Log(DestructibleComponent->IsSimulatingPhysics() ? TEXT("true") : TEXT("false")); // Shows "false"
	DestructibleComponent->SetSimulatePhysics(true); // without this line Actor does not fall down
	GLog->Log(DestructibleComponent->IsSimulatingPhysics() ? TEXT("true") : TEXT("false")); // Shows "false", but actor falls down
}

Problem is Light component does not follow DestructibleComponent’s position.

Light Component in blueprint has set mobility to movable

DestructibleComponent doesnt have such option to choose, SimulatePhysics checkbox also does not appear in blueprint settings.

It’s also a bit confusing why setting simulating physics in BeginPlay allows actor to fall down, but Log shows it’s false

Hey Testerro,

Can you please provide me with the full .cpp and .h file for this class?

Thank you!

Header file:

// Authored by me

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/PointLightComponent.h"
#include "DestructibleComponent.h"
#include "Test.generated.h"

UCLASS()
class UNREALARCHERYSHOOTER_API ATest : public AActor
{
	GENERATED_BODY()

public:
	ATest();

protected:
	virtual void BeginPlay() override;

private:
	UPROPERTY(EditAnywhere)
	UDestructibleComponent* DestructibleComponent;

	UPROPERTY(EditAnywhere)
	UPointLightComponent* Light;
};

.cpp file (just comment and include header else)

// Authored by me

#include "Test.h"

ATest::ATest()
{
	DestructibleComponent = CreateDefaultSubobject<UDestructibleComponent>("DMComp");
	Light = CreateDefaultSubobject<UPointLightComponent>("Light");
	DestructibleComponent->SetSimulatePhysics(true);
	GLog->Log(DestructibleComponent->IsSimulatingPhysics() ? TEXT("true") : TEXT("false")); // shows "false"
	RootComponent = DestructibleComponent;
	Light->SetupAttachment(RootComponent);
}

void ATest::BeginPlay()
{
	Super::BeginPlay();
	GLog->Log(DestructibleComponent->IsSimulatingPhysics() ? TEXT("true") : TEXT("false")); // Shows "false"
	DestructibleComponent->SetSimulatePhysics(true); // without this line Actor does not fall down
	GLog->Log(DestructibleComponent->IsSimulatingPhysics() ? TEXT("true") : TEXT("false")); // Shows "false", but actor falls down
}

Thank you Testerro,

some additional information I’d like to request. Are you currently using unreal engine 4.20? Also, if you could navigate to your UnrealArcheryShooter.Target.cs file, and paste me what you see inside of

public UnrealArcheryShooterTarget(TargetInfo Target) : base(Target)
	{
		Type = TargetType.Game;

		ExtraModuleNames.AddRange( new string[] { // Modules should exist here } );
	}

Thank you!

Yes, I use 4.20.3 version

UnrealArcheryShooter.Target.cs has

public UnrealArcheryShooterTarget(TargetInfo Target) : base(Target)
{
	Type = TargetType.Game;

	ExtraModuleNames.AddRange( new string[] { "UnrealArcheryShooter" } );
}

UnrealArcheryShooter.Build.cs has

public UnrealArcheryShooter(ReadOnlyTargetRules Target) : base(Target)
{
	PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
	
	PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "ApexDestruction" });
	PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
}

It’d be nice to know what’s wrong, because I haven’t found any better solution than crazy manual tracking position in code

Hello,

Try replacing DestructibleComponent->SetSimulatePhysics(true); with DestructibleComponent->GetBodyInstance()->SetInstanceSimulatePhysics(true);

Thanks

Yes! That did the job.
Thank you very much.