Can I force collisions to be checked before Start or manually check collisions?

I’m making a tile based game where the board is mapped out in the editor, and collisions are used with tiles and units to check which tiles are next to each other and which tile a unit belongs on top of. This only happens at the start, of course, because every tile stores its neighbors and resident unit. I remove the rigid bodies and colliders used for collisions in Start.

1 out of 5 times or so (only when using Application.loadLevel()), though, the collisions didn’t seem to run. After some messing around, it seems like collisions aren’t guaranteed to be run before Start() is called, even though it seemed to most of the time.

So there are a few ways I can see solving this, but I’m not sure if I can do it in Unity:

  • Set some kind of parameter that forces collisions to be checked before Start() or even Update()
  • Manually check collisions against one collider or manually check collisions between two colliders using something like Collider.collide(Collider), if that exists.
  • If I can’t do any of that, I’ll just do some manual raycasting and see what it hits.

Are there any other solutions?


How about Physics.OverlapBox or Physics.OverlapSphere ?

I’m not sure you can rely on the physics engine running before Start is called on your objects. Physics is run after LateUpdate. See Execution Order of Event Functions. So I think it’s a freak that any collider calcs are happening before Start because start is called before the first frame update. It sounds like you aren’t really using physics per se, but just want to tell if objects are next to one another. In that case, I’d recommend saving precious cpu cycles in the physic engine and just use raycasting judiciously when needed to detect distance of objects around others.