Best API for many, many calls?

What is the best API to use, when I need to draw tens of thousands of cubes or rectangles?

Currently, if I draw 50k rectangles for my entire map, it takes dozen of ms per frame.
Is there maybe some batch command to speed it up?
Or maybe the fastest possible API call? e.g. box or rect?

Hi

Are these made out of lines, or are they solid rectangles/cubes?

They are solid.

They are in a grid xz, however they have size of 0.8, so they dont touch each other.

Also, it seems Draw.ingame.xz.SolidRectangle does not work as expected with Rect param. Its never on xz plane, always going on Y plane only.

Do these rectangles move every frame, or are they static?

they are static, never move.
However in some cases, I need to add new ones or delete existing ones (as these rectangles represent blocked cells by stuff like props or buildings)

For static ones, you can cache the result like this:

private RedrawScope redrawScope;

void Start () {
    redrawScope = DrawingManager.GetRedrawScope();
    using (var builder = DrawingManager.GetBuilder(redrawScope)) {
        builder.WireSphere(Vector3.zero, 1.0f, Color.red);
        // Draw stuff here
    }
}

void OnDestroy () {
    redrawScope.Dispose();
}

See GetRedrawScope - ALINE

Then it will be basically free every frame (except for the GPU cost).

Ah this is editor only? (it doesnt draw ingame)
I would require API that works “ingame” :slight_smile:

You can pass true as the second parameter to GetBuilder to get one that draws in-game.

1 Like

Thanks! I’ll include a fix for this in the next update too.

1 Like

thank you!

Indeed the param renders it nicely in the game, however there doesnt seem to have any noticable performance gain, if I try to render the spheres on our entire map grid (100x100) (I mean using builder vs rendering it just in Update() loop)

The important thing is that you only render it once during Start. Then the redraw scope will keep it active with very low cost. (at least assuming you are not using any WithPersistent scopes, or InScreenSpace).