Fastest way to check for bounding box partially or fully inside another bounding box?

So I’ve got tonnes of objects (let’s say 200 - not actually sure how many there will be on average). I also have tonnes of bounding boxes (likely also 200). I need to know if one or more of those objects has partially or fully entered one of the bounding boxes. This probably means testing each of the 200 object against each of the bounding boxes (40,000 tests). That’s quite a lot. (Incidentally, it may never reach that amount of objects, but there will definitely be that many bounding boxes, possibly more, so I feel like 200x200 is a good approximation).

So here’s my question: What would be the fastest way to find which of the 200 objects are inside (even partially) which of the 200 bounding boxes?

And: If the best solution does indeed involve 40,000 tests, what would be the easiest and/or best way to split the tests over multiple frames?

Additional Information:

The objects will have various collision shapes attached and be rigidbodies. (Just ignore the fact that I’m running 200 rigidbodies - I have ways to deal with the performance in that respect) I can add box colliders or triggers or whatever is needed to both the objects and the bounding boxes. The bounding boxes themselves are actually parent GameObjects with various meshes and physics stuff as children.

I believe you should look at this problem differently. Don’t try to test if each of the 200 rigid bodies is inside any of the 200 boundaries. Its better to use the system Unity already has for you.

So You have two types of objects, never mind how many there are of each, just that there are two types. And one type will overlap with the other. I have no idea what you have specifically called them but I will simply label these two different groups as “Zones” and “Residents” where a resident can either partially or fully enter a zone. I would use this labels as the name of their collision layer.

The residents will have the Rigid bodies with an attached Box Collider (or what ever shape you want), to represent its bounding volume. The Zones will likewise also have a Collider (with the most valid shape) but set as a Trigger.

Then go to your edit->project settings-> Physics and make sure that Zones and Residents only interact with each other and nothing else, this is mostly an optimization but it also helps in preventing any unexpected triggering events. its here that you’ll also make sure that Zones can’t interact with other zones and the same with Residents and other residents

Finally make a monobehavior script for the zone that uses an OnTriggerEnter, OnTriggerStay, and OnTriggerExit to detect when a resident enters, stays in, or leaves a zone.

also if you want to know if a resident is fully inside a zone you can use this function

bool FullyContains(Collider resident)
    {
        Collider zone = GetComponent<Collider>();
        if(zone == null)
        {
            return false;
        }

        return zone.bounds.Contains(resident.bounds.max) && zone.bounds.Contains(resident.bounds.min);
    }

Now you are no longer constantly checking every frame if 200 objects are messing with a separate groups of another 200 objects, your code is now event driven and will only mess with the objects that it needs to mess with at that specific time.

if you’re curious about Colliders being used as Triggers you can refer to this tutorial
Colliders as Triggers