I think I may have, for the first time, completely hit a wall on what is possible in the Unity engine. I need very large cube terrain, stored very compactly, and I need it to interact properly with the physics engine. This means I need a collider, or set of colliders, that represent the shape of the terrain, which basically requires me to duplicate my map data into a much more verbose format, either turning it into a big polygon mesh, or into a large number of BoxColliders. This would totally destroy any hope of cramming my game into a reasonable amount of memory. (I think I have ways of drawing the terrain efficiently, but that doesn’t help with the physics.)
If I could just subclass the base Collider class, and use that, it would be no problem. It’s trivial to detect collisions against cube terrain. Unfortunately, Unity doesn’t allow that. If you try to add a component to a GameObject, it seems it either has to be one of the set of Component subclasses that they specifically authorize, or a subclass of MonoBehavior.
Is there any other way of doing custom collision detection? Some kind of callback? A way to edit a collision, or decide whether it counts, in OnCollisionEnter or OnCollisionStay?
The best I can think of is to do the check myself every frame on every rigid body, and when they’re colliding with something, create a BoxCollider for the block they’re colliding with, which I keep around only as long as they’re actively colliding with it. This seems way over-complicated, and thus really not an ideal solution, but it may the only thing that will work.