# How do you get a custom mesh to self shadow and cast shadow?

**URL:** <https://forums.unrealengine.com/t/how-do-you-get-a-custom-mesh-to-self-shadow-and-cast-shadow/283788>\
**Category:** World Creation\
**Tags:** Procedural-Generation, cast-shadow, unreal-engine, procedural-mesh, CPP, question\
**Created:** [May 20, 2014, 1:57am UTC](https://forums.unrealengine.com/t/how-do-you-get-a-custom-mesh-to-self-shadow-and-cast-shadow/283788 "2014-05-20T01:57:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DayOfWar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DayOfWar](https://forums.unrealengine.com/u/DayOfWar)\
**Post date:** [May 20, 2014, 1:57am UTC](https://forums.unrealengine.com/t/how-do-you-get-a-custom-mesh-to-self-shadow-and-cast-shadow/283788/1 "2014-05-20T01:57:36Z")

</div>

I have a custom mesh class based on the [Procedural Mesh Generation](https://wiki.unrealengine.com/Procedural_Mesh_Generation)

tutorial on the wiki.

I can’t figure out how to get the GeneratedMeshComponent from the Procedural Mesh Generation tutorial to cast and self shadow.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 20, 2014, 4:15am UTC](https://forums.unrealengine.com/t/how-do-you-get-a-custom-mesh-to-self-shadow-and-cast-shadow/283788/2 "2014-05-20T04:15:07Z")

</div>

#Code For You

Try settings like these.

I use this for all my custom components.

Just put the function in your .h and run it in your constructor for your custom component

```
FORCEINLINE void SetupSMComponentsWithCollision(UStaticMeshComponent* Comp)
{
	if(!Comp) return;
	// ~~~~~~~~
 
	Comp->bOwnerNoSee = false;
	Comp->bCastDynamicShadow = true;
	Comp->CastShadow = true;
	Comp->BodyInstance.SetObjectType(ECC_WorldDynamic);
	Comp->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	Comp->BodyInstance.SetResponseToAllChannels(ECR_Ignore);
	Comp->BodyInstance.SetResponseToChannel(ECC_WorldStatic, ECR_Block);
	Comp->BodyInstance.SetResponseToChannel(ECC_WorldDynamic, ECR_Block);
	Comp->BodyInstance.SetResponseToChannel(ECC_Pawn, ECR_Block);
	Comp->SetHiddenInGame(false);
}
```

---

<div class="post-metadata">

**Author:** ![DayOfWar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DayOfWar](https://forums.unrealengine.com/u/DayOfWar)\
**Post date:** [May 20, 2014, 12:56pm UTC](https://forums.unrealengine.com/t/how-do-you-get-a-custom-mesh-to-self-shadow-and-cast-shadow/283788/3 "2014-05-20T12:56:12Z")

</div>

This doesn’t work for me.  
Can you confirm it works with the Procedural Mesh Generation tutorial?

It will receive a shadow but won’t cast one.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 20, 2014, 5:53pm UTC](https://forums.unrealengine.com/t/how-do-you-get-a-custom-mesh-to-self-shadow-and-cast-shadow/283788/4 "2014-05-20T17:53:06Z")

</div>

I got my own procedural meshes to cast shadows just fine!

#Picture for Reference

 ![6492-dynamicmeshuv.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/7/0/f70068efb3287fbf5a3afe78ce3af9951593cd66.jpeg)

#Movable

Did you set your component to be MOVABLE ??!!

#Set Root Component

Did you set it to be the root component of your Actor that has this component?

#More Code For You

```
AVictoryWallCanvas3D::AVictoryWallCanvas3D(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	//New Root Component!
	VMesh = PCIP.CreateDefaultSubobject < UVictoryMeshComponent > (this, TEXT("VictoryMesh"));
	RootComponent = VMesh;
	
	//Mobility
	VMesh->SetMobility(EComponentMobility::Movable);
	
	//Component Setup
	VMesh->CastShadow = true;
	VMesh->bCastDynamicShadow = true;
	VMesh->BodyInstance.SetObjectType(ECC_WorldDynamic);
	VMesh->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	
	//Just in cases
	VMesh->SetHiddenInGame(false);
}

```

Rama

PS: if this resolves your issue please check mark my post so Epic knows the issue is solved

---

<div class="post-metadata">

**Author:** ![DayOfWar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DayOfWar](https://forums.unrealengine.com/u/DayOfWar)\
**Post date:** [May 20, 2014, 7:02pm UTC](https://forums.unrealengine.com/t/how-do-you-get-a-custom-mesh-to-self-shadow-and-cast-shadow/283788/5 "2014-05-20T19:02:58Z")

</div>

There has got to be something else I am missing .  
I have started all over using the Procedural Mesh Generation tutorial and added the code you suggested with no luck at getting it to cast a shadow.

Receive shadows works and collision works but not casting a shadow.

 ![6665-screenshot00013.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/d/4/1d4b728048c9f1bf75d943fa3ebe8232987a7f0d.jpeg)

---

<div class="post-metadata">

**Author:** ![DayOfWar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DayOfWar](https://forums.unrealengine.com/u/DayOfWar)\
**Post date:** [May 20, 2014, 9:15pm UTC](https://forums.unrealengine.com/t/how-do-you-get-a-custom-mesh-to-self-shadow-and-cast-shadow/283788/6 "2014-05-20T21:15:28Z")

</div>

Finally figured it out.  
Turns out it was the CalcBounds function.  
It was setup like so

```
FBoxSphereBounds UGeneratedMeshComponent::CalcBounds(const FTransform & LocalToWorld) const
{
	FBoxSphereBounds NewBounds;
	NewBounds.Origin = FVector::ZeroVector;
	NewBounds.BoxExtent = FVector(HALF_WORLD_MAX,HALF_WORLD_MAX,HALF_WORLD_MAX);
	NewBounds.SphereRadius = FMath::Sqrt(3.0f * FMath::Square(HALF_WORLD_MAX));
	return NewBounds;
}

```

That turns out to be a very large bounding box and my guess is the shadow rendering code ignores it as if it’s not in the shadow render pass.

To fix it I changed it to represent a more accurate bounding box based on the actual geometry.
