Any way to use static lighting with instanced meshes added in constructor?

I’m using a function to add Hierarchically Instanced Static Meshes during the constructor. I’m then building lighting on the level, including these meshes. The lighting builds perfectly, but as soon as the constructor runs again (ie. when the level is actually loaded in runtime), all the built lighting is obviously lost because the meshes are added again.

Is there any way around this? I need both things ideally: procedurally-added meshes at construction time, and static lighting.

If I manually add instances to a HISM component in Blueprint, they hold the lighting without any problem.

Is there a solution to this?

Use Dynamic Lighting?

Bake lighting information into mesh texture maps?

I can’t use dynamic lighting because it’s too slow. This is for a forest scene in VR. The version with static lighting hits the right FPS, dynamic lighting does not, unfortunately.

How could I bake the lighting information to texture maps? That seems like it would be tricky to do for all the trees. I mean, that’s exactly what lightmass is doing very efficiently for static lighting, I just don’t think there’s any way to pair up the baked light maps with the geometry that gets added back into the scene, even though it’s technically exactly the same geometry as was used in the baking process.

You’d have to rebake the lighting on level load which I’m pretty sure you can’t do.

Do the trees really need to be randomized every time the level loads?

You could instead use a function that does the same thing and just call that from the editor. That way the meshes only repopulate whenever you call the function and you can keep your baked lighting.

The trees aren’t randomised, they’re just populated from an array of transforms read from a text file. So they have the same location/rotation/scale each time.

But ■■■■, I didn’t think of using an editor-only function! Will try that and see if it works. Thanks!

Yeah write a function that runs once in the editor to place all the trees. Then bake map. :cool:

Do you need static lighting actually on those objects with their own Lightmaps? Or do you just want to use static lighting just because it’s cheaper?

If it’s the latter, and if the above suggestions don’t work, have you tried utilizing the Volumetric Lightmaps? 2D Lightmaps on foliage isn’t going to be that great anyway, but the Volumetric Lightmaps can be pre-computed with the empty scene(sky, terrain, static objects) and your dynamically-spawned objects can sample those to receive any nearby bounce/occlusion. You just won’t get any contribution from the dynamic objects on the static objects around them.

Stationary also works. I just ran into this problem. Cheaper than Dynamic.

Is there a way to set static objects to use Volumetric Lightmaps by default? I have only found the drop down on the instances to force it.