Multiplayer - Coin Spawner - Physics2D.OverlapCircleNonAlloc is obsolete

Assuming since I’ve restarted the game with no coins in the walls/objects that my fix is good?

Vector2 GetSpawnPoint()
{
    float x = 0;
    float y = 0;

    while (true)
    {
        x = Random.Range(xSpawnRange.x, xSpawnRange.y);
        y = Random.Range(ySpawnRange.x, ySpawnRange.y);
        
        Vector2 spawnPoint = new Vector2(x,y);

        _coinBuffer[0] = Physics2D.OverlapCircle(spawnPoint, _coinRadius);
        if(_coinBuffer[0] == null) return spawnPoint;
    }
}

Thanks for making go research the two function. My first though was how do you keep the background reporting back that it overlapped. Ah, it only returns collider collisions. It does look like there would be an issue with colliding with things that you don’t mind colliding with. In this game that would be nearly nothing. But for the edge case that a coin trys to spawn in on the point where a shell is currently passing through. It would be registered as an unacceptable position. With the brute force respawn routine it would just pick another point and keep on going.

I would give your procedure my unmitigated, unvetted, two thumbs up.

Yes, this is Unity’s recommended change

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms