Hi everybody,
so this is quite hard to explain, but I do my best:
I’m working on a Voxel Based Terrain (yep, just another minecraft clone) at the moment. I split the world into chunks which are converted into Meshes using UProceduralMeshComponent. To push the performance I moved the generation of the vertex- / index- / color- / normal buffers to it’s own Thread.
I have this graphic which (hopefully) explains what should happen:
If anything is not clear, please let me know. It’s quite hard to explain.
In fact, it works. But not always.
After lots of debugging hours I discovered the bug but I have no idea how to fix it:
Normally chunks are spawned into the world when the game starts. Spawning is handled by an Actor (AVoxelSystem) in BeginPlay(). If the Chunk is spawned it’s constructor requests a mesh regeneration. Then all of the above happens. The Problem is, that once my Code gets compiled (by clicking the compile button in the Unreal Editor) the MeshGenerator starts generating a Mesh although there should be no Chunk. After ‘Publishing’ the DONE Message the MeshGenerator waits for the Chunk to notify the MeshGenerator so it can proceed with the next Chunk. But since there is no Chunk, the MeshGenerator never gets notified.
If I hit play or simulate afterwards there is no new instance of MeshGenerator and the only MeshGenerator instance waits for a Chunk which does not exist to finish its work.
I need a way to get notified by unreals API once the game starts and/or stops so I can clear up the MeshGenerator mess or instantiate new MeshGenerators on the Games Launch. BeginPlay seems like the wrong choice in this case.
I should mention that I do my work in C++ so I’m looking for a Code based approach. If there is no way of solving this in Code I’m happy with a Blueprint approach.
I hope someone can help me and I hope you understand my problem. Explaining something like this is quite hard as a non-native speaker.
[EDIT] I searched for a way in the meantime and I found the Actor Lifecycle ([link text][2]) and I had the following Idea:
Instead of searching a compilicated way I place an Actor in the World which handles all of the MeshGenerator executions. In there I can listen for the BeginPlay and EndPlay events and start/stop/kill Threads. Is something like this is commom/ good practice in Unreal Development?
Best Regards
twinflyer