I have a dungeon random generator that take predesigned rooms from a pool and connect thems. The rooms are prefabs with their own tilemaps, tilemap collider and environmental objects as their child gameObject.
I have a script for the room prefabs with a function (lets call it function A) that check through each tile in the room, run a OverlapAreaAll to see if there’s any collider there, and if there arent, the position is saved in a list as a spawnable point for enemies.
Here lies the problem. I’ve setup a Editor button so that I can manually run function A for each room to test if the function works, and it does. But when I loop through the all the rooms from the roomsManager gameObject and run function A for each, OverlapAreaAll can’t seem to detect any collider.
Does anyone has an idea on what might be going on? Any idea would help as I can’t seem to find anyone with the same problem
Update:
It would seems the problem isn’t with OverlapAreaAll, but with when it’s ran after Instantiating the room prefabs. When I add an IEnumerator to wait for 1 second before running OverlapAreaAll, it can detect the colliders in the child objects of the room just fine. I’m not sure if that’s how it’s supposed to be though or there’s something wrong
There’s no time dependency on any physics query. As soon as you add it, it’s there.
A common mistake is to instantiate a prefab without specifying its position/rotation in the instantiate call and then setting the Transform immediately afterwards. Transform changes don’t get read until the simulation runs which, by default, is at 50Hz so not 1Hz (1 sec).
Either way, it’ll be something you’re doing.
Try creating a collider then immediately querying it. Without fail, it’ll be detected 100% of the time.
2 Likes
I see, thanks a lot for your input. I’ll check it and comeback to you if there’s anything