How do I change a material's sampler at runtime?

I’m using a scrolling material in order to render a background for my game, it works great, but I would like a way to set the images that the material draws from in runtime so I can swap out the backgrounds for each level

There is very little documentation I could find about changing material samplers, does anyone have any jumping off points?

You can use go.set() to change properties on the material, but it depends a bit on the material and component. What kind of component are you using? Is it a sprite or a model quad?

Model quad and multiple texture samplers

I have it set up like this, but for some reason its not recognising the tex1 property off my model when I have it set up in the model.

I’m getting the error

'/BackgroundManager#BackgroundPlane' does not have any property called 'tex1'

As you can see in the bottom right corner, I have it set up as a resource property.

go.property("AudtionBackground", resource.texture("/!!Assets/Background/Textures/BackgroundFrontLayer.png"))

function Backgrounds.SetBackground(self)
	print(go.get("#BackgroundPlane", "tex1"))
	go.set("#BackgroundPlane", "tex1", self.AUDITION_BACKGROUND)
	go.set("#BackgroundPlane", "tex2", self.AUDITION_BACKGROUND)
end

The url is definitely correct, however it breaks on the print statement, I have no idea what I’m doing wrong

So you can go.set(url, "texture0", self.AUDITION_BACKGROUND) texture0texture7

3 Likes