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

I have a custom mesh class based on the 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.

#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);
}

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.

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

#Picture for Reference

#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

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.

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.