I made an actor that allows me to fly through level, throw physics objects around in piles, then automatically convert them to instanced static mesh components and in theory, save them.
However, “Keep Simulation Changes” does not appear to keep the instanced static mesh components that get created (using the “Add Instanced Static Mesh Component” node) - they appear to get thrown away on exiting PIE. I tried to store a reference to the created ISMCs in an exposed array to force them to stay, but it causes a crash (which I reported via the crash reporter with a repro).
I worked around it by just adding a whole heap of InstancedStaticMeshComponents to the compiled actor, and filling those out with instances (not optimal but it works). The instances get stored, but then the static mesh asset assigned to each ISMC does not get saved with “Keep Simulation Changes” either…
So I also worked around that by adding a Call-in-Editor “Fixup” function that goes through the ISMCs and re-assigns the static mesh assets to each (I store the assets in a separate array when I fill out the instances, then I run the Fixup function in the editor after Keeping Simulation Changes). I also use the fixup function to delete the ISMCs I added for the first workaround that weren’t needed.
So it kinda works but could obviously be a lot better. The workaround means I can’t easily add more instances to an existing actor, for example.
You can repro these issues in 4.18:
Repro ISMCs not being kept:
- Create an actor that automatically creates several ISMCs using the “Add Instanced Static Mesh Component” node.**
- Run PIE, select the actor that has the ISMCs in Outliner and “Keep Simulation Changes”.
- Exit PIE & note the instances aren’t there.
Repro ISMCs static mesh change not being kept:
- Create an actor with an ISMC - assign a cube mesh and make a couple of instances and verify they are there when you place the actor.
- On beginplay, change the static mesh asset to a sphere using the “Set Static Mesh” node on the ISMC.
- Run PIE, select the actor that has the ISMCs in Outliner and “Keep Simulation Changes”.
- Exit PIE & note the instances are still cubes.
**if you also want to reproduce the crash, then also add the created ISMCs to an exposed array as you create them. It will crash when you exit PIE after keeping simulation changes.
Note this is blueprint only.