How can I add multiple copies of same object without too many drawcalls?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By drawgy

As far as I know multimesh method just spams the same object on a surface without much manual control. I’m adding trees to my game and if I just copy-paste them, draw calls go up to hundreds and if I add rocks etc. draw calls will grow even more.
So, how can I reduce the amount of drawcalls?

Does this help?
Optimization using Servers — Godot Engine (latest) documentation in English

wombatstampede | 2019-04-25 18:53

:bust_in_silhouette: Reply From: Tim Martin

You’re correct that the “Populate MultiMesh” window from Using MultiMeshInstance — Godot Engine (3.1) documentation in English gives few options and does essentially spam the object around randomly.

But if you attach a script to a multimesh instead, you can control where each instance gets placed in _ready. From the “Making a school of fish” section of http://docs.godotengine.org/uk/latest/tutorials/3d/vertex_animation/animating_thousands_of_fish.html

for i in range($School.multimesh.instance_count):
    var position = Transform()
    position = position.translated(Vector3(randf() * 100 - 50, randf() * 50 - 25, randf() * 50 - 25))
    $School.multimesh.set_instance_transform(i, position)