Unity-Technologies/2d-extras

Error deleting RuleTile with GameObject during physics callback

TheLegendary1248 opened this issue · 2 comments

Unity Version: 2021.3.10f1
2D Tilemaps Extras Version: 2.2.3

Hello, I have a 2D tank game concept that I was prototyping, and I tried to use RuleTiles with GameObjects for detecting which tile was hit due to the Tilemap collider not having builtin methods for just that. That Gameobject has a Box Collider 2D attached and this script

public class Block : MonoBehaviour
{
    public int hp = 5;
    private void OnCollisionEnter2D()
    {
        if (hp-- < 0)
        {
            MasterWallTilemap 
                .stmap //UnityEngine.Tilemaps.Tilemap
                .SetTile(Vector3Int.FloorToInt(transform.position), null);
        }
    }
}

Attempting to set the tile to null during the physics callback gives me this error though
Destroying GameObjects immediately is not permitted during physics trigger/contact, animation event callbacks, rendering callbacks or OnValidate. You must use Destroy instead. UnityEngine.Tilemaps.Tilemap:SetTile (UnityEngine.Vector3Int,UnityEngine.Tilemaps.TileBase) Block:OnCollisionEnter2D () (at Assets/Block.cs:12)

image

I tried looking through docs and issues to remedy the issue, but this is honestly a first where I'm the first to encounter a specific problem

Hi, sorry about this error! This has been fixed with Unity 2021.3.15f1 and you could update your Unity Editor to get it!

Thank you lots, that simply did it

Sorry I mildly glanced over the notice the first time and missed the part where I should have used Unity's bug tracker, thank you nevertheless.