So I have UInstancedStaticMeshComponent that I’m filling with about 10,000 instances to render. Once it is populated, it draws very fast, so no problems there. The trouble is that populating it seems to take some time and causes a very noticeable pause on the main game thread for at least a full second possibly longer. I need to be able to fill the UInstancedStaticMeshComponent at runtime when the player presses a key. I don’t mind if there is a delay between pressing the key and when the instances are finished populating and displaying. I just don’t want the main game thread to pause while its doing it. So I’m hoping this can be solved by running a separate thread. Either using something like FRunnable or the Task Graph. I’m just not 100% sure how to go about this.
Is it even possible to add instances to a UInstancedStaticMeshComponent on a secondary thread? Will that cause problems as the main game thread would most likely be trying to render it while a secondary thread is adding instances to it. Would I need to use some sort of locking perhaps to block rendering of the UInstancedStaticMeshComponent until the secondary thread has finished adding instances? I’ve had a browse through ThreadingBase.h in the UE4 source, but I’m not sure how to accomplish this with the UE4 classes available. There are a lot of classes in there and many don’t make sense to me as to what they are for or how they should be used.
Can anyone help?