I have a function where I am instancing meshes at frame t, then removing them at frame t+1, so that at frame t+2 I can instance a new set of meshes. If I do this with just 1 mesh, no issues. But if do it with 2, one gets removed correctly, whereas the other doesn’t. Similarly with 3 meshes. With 4, 2 meshes gets removed and two don’t. There’s a regularity on the pattern; half of the meshes I’m drawing are not removed by RemoveInstance.
This is how I’m calling the function to remove instances whose ids I’ve stored in an array:
for (int j = 0; j < instanceRef.Num(); j++)
{
myinstancedmesh->RemoveInstance(instanceRef[j]);
}
After a solid debugging session, making sure there were no problems in the code logic or elsewhere (there weren’t) I got to the conclusion there was some problem with the engine. So I resorted to dark magic. This solved the problem:
for (int j = 0; j < instanceRef.Num(); j++)
{
myinstancedmesh->RemoveInstance(instanceRef[j]);
myinstancedmesh->RemoveInstance(instanceRef[j]);
myinstancedmesh->RemoveInstance(instanceRef[j]);
}
Aaaand, the more meshes I’m spawning, the more times I have to call RemoveInstance on the same instance.
Maybe a multi-threading issue?
Cheers
f