Skip to content

Error deleting RuleTile with GameObject during physics callback #373

@TheLegendary1248

Description

@TheLegendary1248

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions