I have a system where physics2d objects are spawned and I need to know when they spawn outside of a region defined by a box collider set to "is Trigger".
Using onTriggerEnter and onTriggerExit to know if an object exits / re-enters the bounds (with some other conditions determining whether to kill the object when it exits the bounds). That stuff works fine.
However I can't detect when an object spawns outside of the collider (which I want to allow, but just know when it happens).
I tried the following in the Start method of the spawned object:
List<Collider2D> results = new List<Collider2D>();
_boundsCollider.OverlapCollider(new ContactFilter2D(), results);
bool spawned_outside = !results.Contains(_thisCollider);
However at the time that method runs, the booundsCollider doesn't register it. Subsequent frames it will, but that's too late.
OverlapCollder can't be run on the collider for the spawned object since it isn't set as a trigger.
Is there any way I can query the spawned object's own collider to determine if it is in contact with the bounds collider?
PS I can't trivially just reference the coords of the object and check if they're out of bounds because the bounds collider will move, and I want to know with precision wether just a corner is overlapping or whatever so I'd need something that amounts to my own simple collision system