Huge CPU spike when erasing a tile at runtime

New Member
Registered: 2017-04-10
Posts: 1


Hello Rotorz people,

I'm trying to destroy tiles at runtime, and it works, however the cpu is getting hit much harder than I would expect it to.

I'm using unity 5.5.0f3 and Rotorz 2.4.4
This is my code:

    private void Update()
        Vector3 mousePos =;
        mousePos.x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x;
        mousePos.y = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;
        mousePos.z = transform.position.z;

        TileIndex tileIndex = tileSystem.ClosestTileIndexFromWorld(mousePos);


This is what I get in the profiler:

And here are my tile system settings:

14ms to erase a tile and 29ms to refresh the tiles around it seems a bit much, so I guess I'm doing something wrong. The brush used is a procedural tileset brush with a simple prefab that contains only a boxColider2D and a kinematic rigidbody attached to it.

Is there any way I can improve this or is this the expected behavior?

Thanks :)!

Last edited by Sclouto (2017-04-10 14:17:38)

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 608

Response 1

Try using this logic instead and let me know whether this performs better for your situation:

if (tileSystem.GetTile(tileIndex) != null)

Procedural tile map updates can be reduced to a single update by applying all changes using the bulk editing mode. This means that the tile mesh only has to be updated one time rather than once per tile change. Bulk editing mode can be nested such that the more expensive changes only occur once the root-most bulk editing has ended.

Tiles are much more static in nature than dynamic sprites are. You may want to consider making things like doors, or destructible walls using sprite prefabs rather than using tiles.

Unity has a certain amount of internal overhead when it comes to instantiating prefabs and destroying game objects, especially when they contain complicated components such as rigidbody's and colliders. If the same tile prefabs are being created and destroyed frequently, then one of the things that you can do to alleviate these pressures is to pool them: … oolmanager

I hope that this helps with your enquiry :)