x

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"

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

Product Version: UE 4.20
Tags:
more ▼

asked Sep 27 '18 at 01:49 PM in C++ Programming

avatar image

Testerro
13 2 2 6

avatar image NicholasMont ♦♦ STAFF Sep 27 '18 at 05:50 PM

Hey Testerro,

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

Thank you!

avatar image Testerro Sep 27 '18 at 06:31 PM

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
 }

avatar image NicholasMont ♦♦ STAFF Sep 27 '18 at 07:55 PM

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!

avatar image Testerro Sep 28 '18 at 07:15 AM

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" });
 }
avatar image Testerro Oct 01 '18 at 08:02 AM

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

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

1 answer: sort voted first

Hello,

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

Thanks

more ▼

answered Oct 08 '18 at 09:58 PM

avatar image

Dakota.Carmer STAFF
36 2 2 1

avatar image Testerro Oct 09 '18 at 02:16 PM

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

(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