Lag when updating a graph

When i pudate a graph the game freezes for 1 second. If you buy the pro version will this stop?

What graph type are you using and how large are your graph updates?

Its a grid.

And the size is 600x560

And how large part of that are you updating?

I am updating the whole graph. Can the player still not move his character while it updates? Will pro version allow this?

Will pro fix this issue? Is that what mutli-threading is?

The pro version does have async scanning ( This does however not guarantee a good frame rate.

If possible I would recommend updating a smaller part of the graph if you are only changing a small part.

The beta version ( has improved performance for scanning grid graphs by using the burst compiler which may also help you.

Im using this to update the graph:
var graph =[1];;

it works but the game freezes for half a second. I really am having trouble figuring this out. How do I update the grid graph the was in the place of the tile (from tilemap) that the player charater just removed in front of him. Any help is much appreciated.

You can read more about updating smaller parts of a graph here:

TL;DR box);

I figured it out. Thank you for your help. Here is the code for anyone else with a similar problem:

if (mainTilemap.GetTile(lPos) != null)

            RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, transform.up*digRange, digRange*2);
            Debug.DrawRay(transform.position, transform.up*digRange*2,, 500f);
            foreach (RaycastHit2D hit in hits)
                if (hit.collider.gameObject != gameObject)
                    cellBounds = hit.collider.GetComponent<Collider2D>().bounds;
            //put dirt in mouth of ant
            if (hunger <= hungerDistress - 10f) hunger += 10f;
            updateNestGraph = true;

            //update graph
            cellBounds.Expand(Vector3.forward * 100);
            var guo = new GraphUpdateObject(cellBounds);
            mainTilemap.SetTile(lPos, null);
            // change some settings on the object
1 Like

It still lags though. In fact the lag might be worse than before.

How large are those cell bounds compared to the whole map?
Does the unity profiler tell you anything interesting?

Its the size of the tile its removing.

That does not answer my question.

Considering how many physics calls that code does, you are updating quite a lot of nodes.

I wonder, why do you have this line in your code?

cellBounds.Expand(Vector3.forward * 100);

because in your notes is says for 2d colliders expand the z component.

Ah. I see.

Do you think you could debug that bounding box and see how large it is?

Use something like

Debug.DrawLine(cellBounds.min, cellBounds.max,, 5);

and post a screenshot of it in the scene view (with the graph visible too)

Your right its huge: cellBounds.min: (-166.1, -1625.9, -50.0) cellBounds.Max: (1146.0, -493.9, 50.0)

1 Like

cellBounds = hit.collider.GetComponent().bounds;

Why doesnt it give me the bounds of the tile it collided with. Its giving me the bounds of the whole tilemap.