Using python code to add objects ( .addObject() ) with unique materials in the upbge

I have an object “A” in a hidden/disabled collection and i use code( .addObject() ) to add it in my game scene. How ever, i want to spawn(add in my game scene) many of this object “A” but with each of them having a different material.
Please i need your help.:sob:

i think itd be easier to just copy the object for each material and then randomly spawn from the list of object names.

or you could use object color to drive various mix factors changing all the parameters. this requires being well versed in glsl nodes and willing to part with some performance possibly.

I know about the first solution, however the number of times i want to spawn the object is enormous (so many) thats why i didn’t use that. As for the second solution, I don’t really understand it.

you can use object color to make one object appear to be using a different material

you can also use vertex color

it’s all up to what you are trying to achieve

to make a unique copy in 3.x

added = own.scene.addObject('objectName',own,0) =

we can edit a game object’s blender object usng bpy in game (assign materials, change vertex colors etc)

This helped. Thanks very much🤗

keep in mind more materials usually means it costs more too render the scene

unique instances of meshes have unique vertex color attribute, and color uniform so use materials sparinglly.

in fact pbr means you can describe any material with 1 shader basically.
(you can even change uv maps layers per unique instance etc)