[SOLVED] How to assign batching in runtime?

Hie everyone,
I know how to set batching in editor on an entity but same thing I want to do in runtime through scripting
for an ex:
I have 8 to 9 materials
and I am assigning randomly 1 material out of 9 material on entities.
So I just want do batching for those entities who got same random value.

Here’s an example doing it: PlayCanvas Examples

Hie @mvaligursky ,
Thanks for sharing this link but after watching this link I am not able to understand how to write code for assigning predefined batch group in runtime
for eg:-
I have already made one batch group id in editor:-

1.) with the name of “Blue” for blue material

Now how can I assign “Blue” batch group for those entities who is having Blue material in runtime through scripting with some line of code ?
.

Hi @PlaycanvasDeveloper, you assign that in each entity’s model/render component:

// find the batch group
const batchGroup = this.app.batcher.getGroupByName('Name of Batch Group');

entity.render.batchGroupId = batchGroup.id;
2 Likes

Thanks @Leonidas
its working .

1 Like