So I have a C++ class which, based on some parameters (Width and Height), I create some dynamic static mesh components using NewObject
I then have a Blueprint sub-class of that component where the actual parameters are set. Currently I create the grid in PostInitializeComponents and in PostEditChangeProperty if WITH_EDITOR is defined at compile time and one of the important parameters changes.
This “works”, except that every time I load the editor, I need to open the BP, change a parameter, save and compile it, then everything works in the editor. After the compile, the preview view port shows the static meshes and I can see it in the main editor view port. If I don’t do this step, the actor never fully initializes and creates it’s sub-components in the editor.
My question is: Is there some other editor level event I should be responding to such that my BP doesn’t have to be re-compiled every time I open the editor? Is there some other way I should be creating dynamic sub-components like this?
Figured it out. I now also implement PostLoad and build the components there. I then track if any of the important properties have changed and only do another build if they have, so it will only build the components once regardless of when I try and build them. It works both in the editor and when playing, and I get the effect that as the BP properties are changed (such as Width) it automatically destroys the old components and builds new ones.
One addition: Also creating the grid on OnConstruction fixed a few more strange edge cases. So I check in all three places if I need to create it (e.g. it doesn’t exist and no properties have changed) and create it if necessary. This basically fixes all the strange edge cases I was dealing with.