Mesh distance field shadows on just a few objects?

In the project settings, there’s an option to “generate mesh distance fields”.

This option enables mesh distance field generation on ALL objects, regardless if the meshes actually have the distance field generation box enbaled or not.

So, what if I just want distance field shadows on a few objects, and not all of them?

The reason for me asking is that I often get this error message in the console after about 2-3000 meshes:

LogStaticMesh: Error: Failed to allocate 64x64x64 in distance field atlas

After that happens, several large meshes I want shadows from often don’t get any, and I can’t increase the detail on others I want in higher resolution.

Just in case someone else is looking for this answer, this is what I learned:

You can’t actually turn off distance field generation with the checkbox (I don’t even know why it’s there at all).

What you can do, however, is set the distance field resolution to 0 for all objects you don’t want distance fields on (you’ll see in the text overlay that their memory footprint won’t just be set to 0, but it will actually disappear).

Also, there is no way to select multiple objects and do this, unfortunately. You need to double click on each static mesh individually and set the option (AND click apply).

A bit counter-intuitive, horribly inefficient, but that’s the way it is as of 4.21. :slight_smile:

You can leave the project setting off and then enable ‘Generate Mesh Distance Field’ on select static meshes. Then you can enable CastDistanceFieldIndirectShadow on the component to get an indirect shadow.

The naming of ‘Generate Mesh Distance Field’ is indeed poor because it makes you think you can use it to disable the distance field, when in reality it can only enable.

Some more info from the comment:

     * Whether to use the mesh distance field representation (when present) for shadowing indirect lighting (from lightmaps or skylight) on Movable components.
     * This works like capsule shadows on skeletal meshes, except using the mesh distance field so no physics asset is required.
     * The StaticMesh must have 'Generate Mesh Distance Field' enabled, or the project must have 'Generate Mesh Distance Fields' enabled for this feature to work.
    UPROPERTY(EditAnywhere, AdvancedDisplay, BlueprintReadOnly, Category=Lighting, meta=(DisplayName = "Distance Field Indirect Shadow"))
    uint8 bCastDistanceFieldIndirectShadow:1;