Hi everyone, Im trying to create a custom Capsule Component inherited from ShapeComponent. Im just clone CapsuleComponent in Engine code and change some variable. Everything’s ok except ShapeComponent::CreateShapeBodySetupIfNeeded();
It would seem that the method CreateShapeBodySetupIfNeeded() is not exposed, unless you want to implement it in Engine Source and rebuild it, you could copy what the function does.
Remove CreateShapeBodySetupIfNeeded<FKSphylElem>();
from UpdateBodySetup()
And sobstitute it with
if (ShapeBodySetup == nullptr || ShapeBodySetup->IsPendingKill())
{
ShapeBodySetup = NewObject<UBodySetup>(this, NAME_None, RF_Transient);
if (GUObjectArray.IsDisregardForGC(this))
{
ShapeBodySetup->AddToRoot();
}
// If this component is in GC cluster, make sure we add the body setup to it to
ShapeBodySetup->AddToCluster(this);
// if we got created outside of game thread, but got added to a cluster,
// we no longer need the Async flag
if (ShapeBodySetup->HasAnyInternalFlags(EInternalObjectFlags::Async) && GUObjectClusters.GetObjectCluster(ShapeBodySetup))
{
ShapeBodySetup->ClearInternalFlags(EInternalObjectFlags::Async);
}
ShapeBodySetup->CollisionTraceFlag = CTF_UseSimpleAsComplex;
ShapeBodySetup->AggGeom.SphylElems.Add(FKSphylElem());
ShapeBodySetup->bNeverNeedsCookedCollisionData = true;
bUseArchetypeBodySetup = false; //We're making our own body setup, so don't use the archetype's.
//Update bodyinstance and shapes
BodyInstance.BodySetup = ShapeBodySetup;
{
if(BodyInstance.IsValidBodyInstance())
{
FPhysicsCommand::ExecuteWrite(BodyInstance.GetActorReferenceWithWelding(), [this](const FPhysicsActorHandle& Actor)
{
TArray<FPhysicsShapeHandle> Shapes;
BodyInstance.GetAllShapes_AssumesLocked(Shapes);
for(FPhysicsShapeHandle& Shape : Shapes) //The reason we iterate is we may have multiple scenes and thus multiple shapes, but they are all pointing to the same geometry
{
//Update shape with the new body setup. Make sure to only update shapes owned by this body instance
if(BodyInstance.IsShapeBoundToBody(Shape))
{
FPhysicsInterface::SetUserData(Shape, (void*)ShapeBodySetup->AggGeom.SphylElems[0].GetUserData());
}
}
});
}
}
}
It builds and it works as well for me.
1 Like