How change material on generated GO with 2 sprites (SOLVED)

I create GO with 2 sprite #l and #r

    body = { --[[000001DB60FF04A0]]
      s1 = hash: [/instance5],
      s2 = hash: [/instance6],
      s3 = hash: [/instance7],
      s4 = hash: [/instance8]
    },

i can set position and etc

go.set(global_.go_robots[data.uid].body.s2, "position.z", -61)

How change material to all sprite in GO ? to this “/robot/asset/material/robot1.material”

i read this resource.material() doc:

I just learned how to do this for my shader materials. Here’s the code I used to do it for the shader:

Defold-Card-Shader-Sample/main/change_shader.script at main · schlista/Defold-Card-Shader-Sample (github.com)

Couple key notes. You don’t need to mess with the timex stuff as I use that to make the shader do stuff.

Also you have to “preload” the material unless it’s used elsewhere on init. That’s why I call them material1, 2, and 3 but never use them. That is just referencing them so they can be found at runtime.

Thanks bro ))

go.property("material1", resource.material("/assets/materials/rainbow.material"))

and

self.rainbow = hash("/assets/materials/rainbow.materialc")

its one file rainbow.material or different?

I edited my last reply to your post to add this in (accidentally sent the reply before I finished typing, oops…) but there’s a much simpler way of doing it instead of having to manually hash the material path:

go.property("my_material", resource.material("/material.material"))
function init(self)
  go.set("#sprite", "material", self.my_material)
end

You can get the address of the generated sprites like so:

local s1_l = msg.url(nil, body.s1, "l")
local s1_r = msg.url(nil, body.s1, "r")

go.set(s1_l, "material", self.my_material)

This work only in script? how about module?

or use msg.post from module to script?

or i make in init()

go.property("my_material", resource.material("/material.material"))

and after in module

local s1_l = msg.url(nil, body.s1, "l")
local s1_r = msg.url(nil, body.s1, "r")

go.set(s1_l, "material", self.my_material)

Put that wherever it is that you need to change the material of those sprites. I don’t know the layout of your project so I can’t give a more specific answer.

When referring to files you have to add a c to the end of it. (I just learned this too). See this thread.

Yes, yes - i read this

Many thanks, i ll try it