# How to programmatically enable gravity on a UGeometryCollectionComponent

**URL:** <https://forums.unrealengine.com/t/how-to-programmatically-enable-gravity-on-a-ugeometrycollectioncomponent/1332736>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, geometry, CPP\
**Created:** [October 14, 2023, 10:46pm UTC](https://forums.unrealengine.com/t/how-to-programmatically-enable-gravity-on-a-ugeometrycollectioncomponent/1332736 "2023-10-14T22:46:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rstojano](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rstojano](https://forums.unrealengine.com/u/rstojano)\
**Post date:** [October 14, 2023, 10:46pm UTC](https://forums.unrealengine.com/t/how-to-programmatically-enable-gravity-on-a-ugeometrycollectioncomponent/1332736/1 "2023-10-14T22:46:48Z")

</div>

I have an actor class called ABreakableActor which holds a:  
UGeometryCollectionComponent\* BreakableMeshComponent;

I have inherited this class with a BP that disables the gravity of the component so it just floats there. I would like to enable gravity on the object when certain events happen in the game but it seems to have no effect. For example, if I try overriding BeginPlay:

```auto
void ABreakableActor::BeginPlay()
{
	Super::BeginPlay();

	BreakableMeshComponent->SetEnableGravity(true);
}

```

There is no effect on the gravity of the object.

For reference here is the constructor:

```auto
ABreakableActor::ABreakableActor()
{
	PrimaryActorTick.bCanEverTick = true;

	// Initialize and set DefaultSceneRoot as the root component
	DefaultSceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultSceneRoot"));
	RootComponent = DefaultSceneRoot;

	// Create BreakableMeshComponent and attach it to the DefaultSceneRoot
	BreakableMeshComponent = CreateDefaultSubobject<UGeometryCollectionComponent>(TEXT("BreakableMeshComponent"));
	BreakableMeshComponent->SetupAttachment(DefaultSceneRoot);
}

```

---

<div class="post-metadata">

**Author:** ![rstojano](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rstojano](https://forums.unrealengine.com/u/rstojano)\
**Post date:** [October 17, 2023, 10:20pm UTC](https://forums.unrealengine.com/t/how-to-programmatically-enable-gravity-on-a-ugeometrycollectioncomponent/1332736/2 "2023-10-17T22:20:05Z")

</div>

I discovered that calling SimulatePhysics doesn’t work in the BeginPlay() method on the CPP side, so you need to call it on the BP side.

What I ended up doing was this:  
void ABreakableActor::BeginPlay()  
{  
Super::BeginPlay();

```
BreakableMeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
// These 2 lines of code don't actually work when called from CPP for some reason.
// DONT FORGET TO SET THESE IN THE BP!
BreakableMeshComponent->SetSimulatePhysics(false);
BreakableMeshComponent->SetEnableGravity(false);

```

}

Hopefully, this will help someone in the future!
