Creating buoyancy pontoon in C++

I’m trying to add Buoyancy pontoons to a ship in C++.
I can do it in BP.
My Flotation component is created.
If I activate r.Water.DebugBuoyancy I see the red spheres on the included test cube, but not on my C++ Ship.
I’m calling the function AddBuoyancy() in OnConstruction. But I have tried it in the construct as well (with createdefaultsubobject) with same negative result.

The hull is the root, But I can’t see a command to attach the flotation to the root. In the BP childclass I see that the Flotation is separated by a line (?) and there is no details for it.
Buoancy not working

void AShipTemplete::AddBuoyancy()
{
	UBuoyancyComponent* Flotation = NewObject<UBuoyancyComponent>(this);
	if (Flotation)
	{
		Flotation->RegisterComponent();
		Flotation->AddCustomPontoon(80, FVector(400, 0, 40));
	}
	else {
		UE_LOG(LogTemp, Warning, TEXT("There is no Buoynacy component added"));
	}
}

Solved it!

You have to add the BuoancyComponent on BeginPlay. Can’t do it in the constructor or OnConstruction. I Guess the rootcomponent need to be fully initialized before adding it

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.