I have a game where everything is made of 0.1m^3 voxels, and models of them have it so the voxels are only visible/colliding on the outer surface area, not inner. Does anyone have any idea how you could create a seperation mechanic for detecting when a model has been seperated into two models? Im not asking for a script, but how would you go about programming that?

@Benproductions1 is onto something, and should be given some credit as it inspired the following answer. But indeed a brute force approach would be too computationally expensive.

These are my thoughts: if all you need is to verify if a model has split in two and simply obtain a true/false value, you don’t need to test if you can reach ALL voxels from ALL other voxels.

All you need is to find if there exists at least ONE voxel that you cannot reach ONE other voxel from.

In this context, think about the simple case in which a single voxel is removed. Most voxels in the model are unaffected. Only those that were neighbours of the removed voxel are, and those are just 6 or 26 depending if you count diagonal neighbours. You can therefore restrict your search to those and find if there exist one of them from which you cannot reach another.

Not only. Let’s switch to 2D for simplicity:

NCN
NRN
TTT

Assuming R is the removed voxel and C is the first voxel to check, all the voxels marked N are obviously neighbours of C, and as long as they exist there will always be a path to them from C. So, you don’t need to test if C and the Ns are connected. And you don’t even need to test for their existence. What you need is to test if you can reach from C the voxel marked as Ts, as they aren’t neighbours of C. If even just one of them isn’t reachable the model has been split in two.

Obviously the pathfinding required for arbitrary models is non trivial, but thinking only about neighbours of the voxel(s) removed should be a considerable performance boost.

If that is not enough I am afraid you might have to get into things such as space partitioning and model simplification. I.e. if you have a 5x5x5 cube it might be worth to keep only the outer layer of voxels as separate entities. The 3x3x3 inner core could be simplified into a single entity for the purpose of pathfinding, to be split again in 3x3x3 voxels if it becomes exposed to the outside, i.e. when one of the outer voxel is removed.

Hope it helps.