#Physics queries - Active object order

1 messages · Page 1 of 1 (latest)

olive wing
#

I have this experimental Coin Magnet system that uses OverlapSphere to pick up nearby coin objects. CoinSpawner and CoinMagnet are essentially in the same position.
https://paste.mod.gg/epzrdlrwhbdm/0
Ideally, coins that are not within the magnet's range should not be registered to the _magnetizedCoins list. But in the first version, in CoinSpawner where I set new coin objects to be active before setting its new position, some coins seem to be Magnetized, even though they are out-of-range. They are also disabled and with Magnetized == false when the pool releases them. When I change the order, and set the coins active only after setting their new positions, it works normally.
There is no stop in the spawn instruction, so my only guess is that OverlapSphere somehow takes over in the middle of the action. Is it probable that the Physics queries can pick up the colliders right after they are set to be active?

dense robin
#

You need to call Physics.SyncTransforms() if you want the physics world to immediately update after moving an object. Otherwise, the changes will only show up after the next physics update

#

It's been a while since I dug into this. I remember helping someone with this for a ship-building system – it would find colliders in bogus locations

dense robin
#

which would explain why activating the coin after positioning causes the bug to go away

olive wing
dense robin
#

Yeah – Unity won't immediately tell the physics system that you moved the object. There is an "auto sync Transforms" option in the project settings

#

but that's going to come with a performance penalty, I imagine