# Inherited Shape Component

**URL:** <https://forums.unrealengine.com/t/inherited-shape-component/447032>\
**Category:** C++\
**Tags:** c-build, custom-component, unreal-engine, Visual-Studio, CPP, question\
**Created:** [April 11, 2019, 12:16pm UTC](https://forums.unrealengine.com/t/inherited-shape-component/447032 "2019-04-11T12:16:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_92e84e05](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_92e84e05](https://forums.unrealengine.com/u/anonymous_user_92e84e05)\
**Post date:** [April 11, 2019, 12:16pm UTC](https://forums.unrealengine.com/t/inherited-shape-component/447032/1 "2019-04-11T12:16:53Z")

</div>

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();

 ![273909-customcapsule2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/e/a2e21cd85d3fb09581ae40e9704aa314c85bd206.png)

 ![273908-customcapsule1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/2/5/52525bb390552ba400ce2690b21e96569ba9adf9.png)

---

<div class="post-metadata">

**Author:** ![Coratti.S](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Coratti.S](https://forums.unrealengine.com/u/Coratti.S)\
**Post date:** [August 7, 2021, 11:32am UTC](https://forums.unrealengine.com/t/inherited-shape-component/447032/2 "2021-08-07T11:32:08Z")

</div>

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.
